开发者

Why does this css not produce a background image?

开发者 https://www.devze.com 2023-02-20 11:37 出处:网络
body{ background:#fff url(\'images/testProfile.jpg\') no-repeat right top; } I assume this code should work so please suggest useful debugging steps...e.g. how to adjust image properties and positio
body{    
background:#fff url('images/testProfile.jpg') no-repeat right top;
}

I assume this code should work so please suggest useful debugging steps...e.g. how to adjust image properties and position in extreme 开发者_运维百科ways...


Keep in mind that url() in CSS is relative to the stylesheet and not the page. This might be a problem here.


Most likely because the image isn't being found. Look at the images loaded via the dev tools of a good browser (Like Chrome, Safari or Firefox + firebug). You should be able to see images it tried to load along with the server responses for them. If it's a 404, then you have your image path wrong.

And remember that the image urls are always relative to the stylesheet location, not the page itself. So the relative path may be different than you think.


Debugging example

This page: http://jsfiddle.net/qUfn9/

With css: body { background: url('foo.png') }

Makes the chrome dev tools say this:

Why does this css not produce a background image?


try using an absolute path for the url

body{    
background:#fff url('/images/testProfile.jpg') no-repeat right top;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消