tags:

views:

81

answers:

4
+1  Q: 

referencing CSS

Hi, I would like to construct an HTML link element referencing a CSS file and I would like to use the same reference from multiple documents.

For example, my CSS file is in: {root}/style/style.css

For files in {root}, I use: <link type="text/css" rel="stylesheet" href="style/style.css" /> But for files in {root}/inc, I have to use <link type="text/css" rel="stylesheet" href="../style/style.css" />

Is there a reference to {root} that I can use: something like:

<link type="text/css" rel="stylesheet" href="{root}/style/style.css" />

Sorry for noob question and thanks!

+6  A: 

A simple / usually means "start from root"

Jonathan Sampson
to clarify, hrefs that start with /, as in /foo/bar, are relative to the root of the domain; hrefs that don't (and don't include a domain) are relative to the current directory.
DDaviesBrackett
+2  A: 

Just start the URL with a slash, the {root} is implicit:

<link type="text/css" rel="stylesheet" href="/style/style.css" />
yjerem
A: 

You could use the <base> element: Rec, but unfortunately, this will also have impact on any other, normal hyperlink in your page.

If you use XHTML (the real stuff, nothing for IE users), take a look at xml:base.

Cheers,

Boldewyn
+2  A: 

This will work

<link type="text/css" rel="stylesheet" href="/style/style.css" />

If you have a "/" at the beginning of a file reference, it means it is an absolute reference starting at the root. Without the "/" it would be a relative reference to {wherever-your-document-is}/style/style.css.

Andrew Marsh