Welcome to WebmasterWorld Guest from 23.22.140.143

Forum Moderators: not2easy

Message Too Old, No Replies

external CSS - How do you specify css file using an absolute path?

How do you specify css file using an absolute path?

     
11:50 pm on Apr 27, 2009 (gmt 0)

New User

5+ Year Member

joined:Mar 17, 2009
posts:27
votes: 0


Hi Friends,

I am new to CSS and HTML, so this might be a very trivial question. I have a directory named "htdocs/css", where I store all of .css files. Then I have various webpages "htdocs/dir-1/.../dir-n/index.html" spread all around in htdocs directory for different parts of the site. I want to link the each index file with respective .css file using an absolute path like
<LINK ....... href="$somevariable/css/example.css >

and not a relative path like

<LINK ....... href="../../css/example.css >

is there a way I can do it? Please let me know

Thanks
Su Ti

12:10 am on Apr 28, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 7, 2003
posts:4783
votes: 0


Presuming that htdocs directory is where your documentroot is.

Try:

in HTML:
<link rel="stylesheet" type="text/css" href="/css/example.css">
in xhtml:
<link rel="stylesheet" type="text/css" href="/css/example.css" />

Put that in your head section.

2:10 pm on Apr 28, 2009 (gmt 0)

New User

5+ Year Member

joined:Mar 17, 2009
posts:27
votes: 0


Thanks SWA,

That worked beautifully. Really appreciate your quick responce.

Cheers
Su

9:33 am on June 1, 2009 (gmt 0)

New User

5+ Year Member

joined:June 1, 2009
posts:1
votes: 0


I have a similar problem.

I have a file head.php which contains all the links to css files and script files (basically everything that goes in the <head> tag).

If I include that file in two pages, one in the root folder and one in a subfolder, the one in the subfolder will not be referenced properly since the link to the css file is relative to the root folder:

<link type="text/css" src="css/style.css" />

Adding the '/' to the front of the filepath does not resolve the issue in this case.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members