Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

css base url

Is there a way to tell a CSS file to always use a base URL just like href?



2:44 pm on May 31, 2008 (gmt 0)

5+ Year Member

As I am looking at this more and more. If I utilize the http protocol for my includes within my php files rather than ../ this should solve my issue. This is more of a php question than a CSS question. Please move this to the appropriate forum with a different header. That would be PHP relative includes vs. PHP absolute includes.

I have a minor issue.

I am using relative locations (ie. ../)for my images found within my CSS file.

This has been working great as long as I keep everything I do in the root directory. I started utilizing different directories to keep my code in and found out that the further I go away from the root directory the more issues I am starting to have utilizing the above method. (This goes the same for my JS file directory)

Reference the chart below The problem that is happening is when the public directory attempts to access the css file it looks for the css file as support/css/css.css rather than root/css/css.css

I utilize multiple include files and have massive amounts of code to make everything on the website work together so I cannot re-write everything and start over again.

Without rewriting everything and moving everything into different directories, I would like to be able to utilize the same php include files and the same CSS, JS, Image files, etc so that when I make a change to the website I only have to do so in 1 file to make it site wide.

Root Directory has the following directories:
(You will notice that in the Root there is are CSS, JS, Images and Support Directories. You will also notice there is a Public Directory located within the Support directory. This is where the issues is at.)


CSS --> All Images Referenced as ../Images/
Support --> Public --> References A CSS.PHP file as ../../css.php

A portion of the contents of the CSS.PHP are:
<link rel="stylesheet" type="text/css" href="../css/css.css" />

I thought about utilizing absolute references but by personal preference would like to stick to relative references.
What do you think?
Any ideas?


3:41 pm on May 31, 2008 (gmt 0)

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

Welcome aboard scrfix! As for the original question, I am not sure - however there is a really good way to "start at root" across all your markup - CSS, Javascript, and HTML. Instead of


Always use


The / means start at the domain root. So you can move a file containing this


**anywhere** on your site and it will always locate file.html.

The same is true in your scripts,

$css = '/css/scripts/scripts.css';

and your css

background: url(/images/some_dir/image.gif);

The down side: requires a web server; working on these files locally on either PC or Mac will not find the locations. You can temporarily revert to relative using a S & R function in your editor.


3:31 am on Jun 1, 2008 (gmt 0)

5+ Year Member

That's awesome. I was knocking my head around attempting to figure that out. I thought it was ./ but that didn't work. I tried everything but that. I even tried ../../../../ just to ensure that I was in the root. lol (That didn't work either).

(I have actually been a member of webmasterworld for quite some time but my original username and password were not working and the password recovery page was non existent. I had to create a new username.)




9:15 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

. (or ./) means the current directory
.. (or ../) means the parent of the current directory
/ means the root directory

so ../../../../ means go "up" 4 directory levels.


3:18 pm on Jun 1, 2008 (gmt 0)

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

I even tried ../../../../

Been there, driven insane, barely recovered. :-)


3:40 pm on Jun 1, 2008 (gmt 0)

5+ Year Member

Thanks Everyone. *SCRFix Dances a Jig, So Happy*

Featured Threads

Hot Threads This Week

Hot Threads This Month