Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting the relative path for background image in stylesheet

Status
Not open for further replies.

VJay

Programmer
Mar 26, 2002
19
IN
Hello:
Problem:
I have all the images of my site in the Images sub directory. When I specify the background image in the stylesheet using relative path this doesn't work. The code in the stylesheet is:
background-image: url(Images/arrow_nxt_dis.gif);

Instead if I use the following code and move the image to the root directory it works, Which I dont want to do:
background-image: url(arrow_nxt_dis.gif);

It also works for the following code:
background-image: url(

Is it possible to specify the relative path like in the first scenario, Pls lemme know.
Thanks
Vjay
 
Question. Is your images folder named Images or images?
 
Hello Jacob
Images folder is named "Images"
But does that matter?
Thanks for ur response
Vjay
 
case really doesn't matter - So images or Images - they are both the same.

Firstly - make sure you are referenceing the right file name (just I see you are calling arrow_nxt_dis.gif and arrow_nxt.gif).

try -

background-image: url("Images/arrow_nxt_dis.gif");

I would try this out on my local server - but I haven't got the time - so let me know if this works. If not - I'll setup a test myself.
 
Do it from the root?
/epss/epss_features/vyje/images/arrow_nxt.gif

Or do you not want to do this?

And incase case-sensitivity DOES cause a problem make sure it is "images", just in case.



::
 
Ah - I've just been reading up on this for you.

Here is what the W3C say about relative paths:
(basically saying that the path is relative to the CSS file not the HTML file calling it!)

For example, suppose the following rule:

BODY { background: url("yellow") }

is located in a style sheet designated by the URI:

The background of the source document's BODY will be tiled with whatever image is described by the resource designated by the URI


so if your HTML file and the CSS file are in the same folder then it's gonna work how you would expect - but if not then things are gonna get messed up!

Hope this helps a little further!
 
All I know is if I use: background: #000 url('Images/picture.gif');, it will not work since my images folder is named 'images'.
Also you should specify a background color in case the image doesn't show up for some reason.
 
McFlyTheBassist
Of course it HAS to be relative to the CSS file, it would be different if you were using includes or something to put those styles within the HTML document.

I still reckon from the root is the best way. :)


::
 
Thank u guys esp. McFlyTheBassist. For bringing into light the fact the path is relative to the CSS file.
 
McFlyTheBassist

case really doesn't matter - So images or Images - they are both the same.

On a Windows server case does not matter.
On a *nix server, Images, images & iMaGeS are 3 totally different directories and the correct file will only show if the case is correct.

Hope this helps
Wullie

- Send your letter to santa!!

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top