简体   繁体   English

背景图片不会显示

[英]Background image wont show up

I have a background image that I want to repeat across (repeat-x) however when I try to view the page, nothing shows up. 我有一个背景图片,我想重复该图片(repeat-x),但是当我尝试查看该页面时,没有任何显示。 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. 我还使用javascript在一天中的不同时间使用不同的CSS文件,但是我确信这不是问题,因为Firebug表明CSS文件已添加到头部。

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. 您可以在此处下载该站点的存档: http://cdn.duffcraft.net.adam543i.net/sitebkp-1845.zip : http://cdn.duffcraft.net.adam543i.net/sitebkp-1845.zip它只有200 kb。 Nothing massive. 没什么大不了的。

As there is no text in your header the div will not get displayed.Try following css 由于标题中没有文本,因此div将不会显示。请尝试按CSS

#header {
    background-image:url(img/night/night-time-tile.png);
    background-repeat:repeat-x;
    position:absolute;
    height:100px;  // Adjust height according to your image height 
    top:0;
    left:0;
}

And you are sure the path to your image file is correct? 并且您确定图像文件的路径正确吗? Does Firebug load the image? Firebug是否会加载图像?

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. 现在,您必须从style.css中使用图像文件的相对路径。 So not img/night/night-tile.png but ../img/night/night-tile.png . 因此不是img/night/night-tile.png而是../img/night/night-tile.png In your path it is looking for the image within the css directory, which is wrong. 在您的路径中,它正在css目录中寻找图像,这是错误的。

==Update== == ==更新

After downloading your code I found 2 more errors. 下载您的代码后,我发现了另外2个错误。

The first is that you forgot to add rel=stylesheet to the <link> element in which you link to your stylesheet. 首先是您忘记将rel=stylesheet添加到<link>rel=stylesheet<link>元素中。 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. night.css第一个规则的night.css ,导致解析错误,导致背景规则无法呈现。

Good luck fixing these issues! 祝您好运解决这些问题!

If you have the Chrome browser, inspect the element where the background image should appear. 如果您使用的是Chrome浏览器,请检查应显示背景图片的元素。

Hover over the background-image declaration in the firebug window 将鼠标悬停在萤火虫窗口中的背景图像声明上

background-image:url(img/night/night-time-tile.png);

and you will see the full path of the image. 您将看到图像的完整路径。

In the screenshot you can see the equivalent for the stackoverflow logo at the top of the page. 在屏幕截图中,您可以在页面顶部看到与stackoverflow徽标等效的徽标。

You can then click on the css declaration and change the url until you find the correct path for your image. 然后,您可以单击css声明并更改url,直到找到图像的正确路径。

在此处输入图片说明

The element has no height (either explicit or from content). 元素没有高度(显式或内容高度)。

This means there are no visible pixels of the element to see the image across. 这意味着该元素没有可见的像素可以看到整个图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM