且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

背景图像不会出现

更新时间:2022-10-19 13:03:46

你确定图像文件的路径是正确的? Firebug会加载图片吗?

您的文件结构可能是这样的

  index.html 
css /
style.css
img /
night /
night-tile.png

现在,从您的 style.css ,您必须使用相对路径来映像文件。所以不是 img / night / night-tile.png 但是 ../ img / night / night-tile.png 。在你的路径中,它正在寻找 css 目录中的图片,这是错误的。 $ b = =更新==



下载您的代码后,我发现2个更多的错误。 ; 你链接到你的样式表的元素。这样,浏览器就不会知道它是样式表。



第二个是你忘记在中添加$ c>您的 night.css 中第一条规则的结尾,导致出现分析错误,导致不显示背景规则。



祝你好运解决这些问题!


I have a background image that I want to repeat across (repeat-x) however when I try to view the page, nothing shows up. I'm also using javascript to use a different CSS file for different times of the day, however I am sure that is not the problem because firebug shows that the CSS file was added to the head.

Edit: The problem is that the browser cannot find the file, however when I attempt to link to it, it still cannot find the file.

You can download the archive of the site here: http://cdn.duffcraft.net.adam543i.net/sitebkp-1845.zip Its only 200 or so kb. Nothing massive.

And you are sure the path to your image file is correct? Does Firebug load the image?

Your file structure is probably like this

index.html
css/
    style.css
img/
    night/
        night-tile.png

Now, from your style.css you have to use a relative path to your image file. So not img/night/night-tile.png but ../img/night/night-tile.png. In your path it is looking for the image within the css directory, which is wrong.

==Update==

After downloading your code I found 2 more errors.

The first is that you forgot to add rel=stylesheet to the <link> element in which you link to your stylesheet. This way, browsers will not know it's a stylesheet.

The second is that you forgot to add a ; at the end of your first rule in your night.css, resulting in a parse error which causes the background rule not to be rendered.

Good luck fixing these issues!