开发者

stylesheet reference issue

开发者 https://www.devze.com 2023-03-04 23:19 出处:网络
I have a stylesheet defined in the index.html as <link rel=\"stylesheet\" type=\"text/css\" href=\"css/template.css\">

I have a stylesheet defined in the index.html as

<link rel="stylesheet" type="text/css" href="css/template.css">

Inside the template.css, I have declared

body{
background-image: url(images/background.png);
b开发者_如何学Cackground-repeat: repeat;
}

Why is the image not getting displayed? The path is correct


The path in the CSS should be relative to where the CSS file is located, not from where the page where the CSS file is being loaded from.

Try:

background-image: url(../images/background.png);

When you are starting out, this can seem counter intuitive, but it's actually a good design as your CSS file can then be called from any page in any folder and the references to the images will not be broken.

0

精彩评论

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

关注公众号