tags:

views:

129

answers:

6

I have this in my CSS file:

body {style.css (line 3)
background:#CDF8FF url(images/final_bg.jpg) no-repeat scroll center top;
clear:both;
font-family:Arial,Helvetica,sans-serif;
margin:0;
padding:0;
}

That images exists, as I can get to it via the browser, but it is never displayed to me! What is wrong?

I use firebug to see if its there, every time I put my mouse over it, firebug just shows a loading icon to indicate its not there.

Thanks to anyone that can clear this confusion.

Btw, I have cleared my cache several times! I am using Firefox on my Fedora Linux box.

+2  A: 

It's a relative URL. Should it be /images/final_bg.jpg?

Look at your web server's access log and see what's being requested.

Also, in Firebug, look at the network traffic -- are you seeing the request you expect and a success response (200)

Edit: corrected based on David's comment

Lou Franco
Since we don't know the URL of the stylesheet, we can't know that that is the right URL for the image.
David Dorward
the 10k upvote is mine!
dfa
huh? The image has an absolute URL -- you can use that anywhere. I believe it's relative to the page, not the stylesheet.
Lou Franco
dfa -- you totally rock! -- been trying to get to 10k this week.
Lou Franco
@Lou the URL you give is absolute. The one is the stylesheet is not ... ah, I think you are missing a question mark at the end of line 1 of your answer.
David Dorward
@David Dorward: It’s an absolute URL *path* and not an absolute URL. Absolute URLs do always begin with the URL scheme.
Gumbo
+3  A: 

Odds are that the specified image doesn't really exist.

A common mistake is to place an HTML document at:

http://example.com/foo.html

with a stylesheet at

http://example.com/css/style.css

referencing an image at

http://example.com/css/images/final_bg.jpg

but actually putting the image at

http://example.com/images/final_bg.jpg

URLs in stylesheets are relative to the stylesheet, not documents which reference that stylesheet.

Move the image, or change the URL (to start with a / in the above example)

David Dorward
I think you mean that the actual Url doesn't reference the existing image. If he can get to the image by specifying a URL I think we can be sure it exists, but it's mostly likely in a different place than expected as you've described.
tvanfosson
David, you are right. I didn't know that.
Abs
+1 this answer is better than mine since it explains my bet! :)
dfa
The mistake is just the assumption that the base URI is always the URI of the HTML document.
Gumbo
A: 

try using an absolute path, especially if your css is in an external stylesheet.

url(/images/final_bg.jpg)

If that does not work try adding quotes

url('images/final_bg.jpg')

Hope this helps!

Patcouch22
The quote advice is bogus. They are optional. (And single quotes actually break IE5/Mac)
David Dorward
A: 

I bet on ../images/final_bg.jpg:

background:#CDF8FF url(../images/final_bg.jpg) no-repeat scroll center top;
dfa
A: 

you need to put the path inside quotes:

background:#CDF8FF url('images/final_bg.jpg') no-repeat scroll center top;
Philippe Mongeau
Quotes don’t make any difference here. They are just needed if you want to use some characters you can’t use in that context and don’t escape them (such as the closing parenthesis in `url("foo().png")`).
Gumbo
+2  A: 

If you use relative URIs in your stylesheet, you need to make them relative to the URI of the stylesheet.

So if your stylesheet is in /css/style.css, you need to use ../images/final_bg.jpg to reference /images/final_bg.jpg correctly (or you use the absolute URI path /images/final_bg.jpg).

Gumbo
You are a legend.
Abs
there are about 5 answers like this... and gumbo is a legend? are you joking?
dfa
First one, I saw and it worked. Don't be picky with comments.
Abs