[英]css background-image won't display in IE or Chrome
I am attempting to use background-image:url('path/to/image.png'); 我正在尝试使用background-image:url('path / to / image.png'); to place a background image in a div by ID:
通过ID在div中放置背景图片:
#logo_block > #main_logo {
background-image: url("img/JaxonsBlack.png");
width:450px;
height:auto; }
and the html is as such: 和HTML是这样的:
<div id="logo_block">
<!-- This will remain static. -->
<div id="main_logo">
<!--<img id ="logo" src="img/JaxonsBlack.png" width="400" />-->
</div>
<!-- This div will be dynamically populated in the future
it resides immediately under the logo image-->
<div id="sub_title">
<h3>sample</h3>
</div>
</div>
Ok, so no matter what I try, I can't get this to work. 好的,所以无论我如何尝试,我都无法正常工作。
its not a pathing issue. 这不是一个棘手的问题。 The img tag in the html below works fine when its not commented out.
如果未注释掉,则下面html中的img标签可以正常工作。 I can apply the very same CSS to the body and it works fine as well.
我可以将相同的CSS应用于主体,并且效果也很好。
Selectors. 选择器。 Its not those.
它不是那些。 I look at Chrome's developer tools and the style is being applied to the div appropriately.
我看了一下Chrome的开发人员工具,并将样式正确地应用于了div。 I have also removed the div from the parent div and used simply #main_logo as the selector, tried a class, etc etc etc.
我还从父div中删除了div,仅使用#main_logo作为选择器,尝试了一个类,等等,等等。
Height. 高度。 its not the height style.
它不是高度样式。 I've seen that mentioned, and with or without height, width, etc, it still doesn't work.
我已经看到了提到的内容,无论高度,宽度等有无,它仍然不起作用。
I can't seem to find any info on this issue anywhere. 我似乎在任何地方都找不到有关此问题的任何信息。 My syntax is correct as far as I can see, and multiple sites support that.
据我所知,我的语法是正确的,并且多个站点都支持该语法。 This doesn't work in Chrome or shudder IE.
这不适用于Chrome或颤抖的 IE。 My FF install is currently broken (again) so I haven't tried it there.
我的FF安装当前已损坏(再次),所以我没有在那儿尝试过。 I somehow doubt it'll be any different, but if it doesn't work in Chrome or IE, I still need to figure this out.
我以某种方式怀疑它会有所不同,但是如果它不能在Chrome或IE中运行,我仍然需要弄清楚这一点。
I'm at my wit's end on this. 我在这方面机智。 It simply doesn't make sense.
这根本没有道理。
height
is set to auto
, so it'll only be as tall as it needs to be to show all the content, but there's no content in there, hence it's 0px tall. height
设置为auto
,因此它只能显示所有内容所需的高度,但其中没有内容,因此高度为0px。 http://jsfiddle.net/Z632P/ - change the height
to auto
then back to 100px
. http://jsfiddle.net/Z632P/-将
height
更改为auto
然后返回100px
。
Try: 尝试:
height: 100%;
instead. 代替。
If it's working in other browsers, this should fix it. 如果它在其他浏览器中也可以运行,则应该对其进行修复。
Is your style defined in a separate css file? 您的样式是否在单独的CSS文件中定义? If so, the path should be relative to the css file, not to the html file.
如果是这样,则路径应相对于css文件而不是html文件。 So if you have your css file in /styles/blah.css and you have the url img/JaxonsBlack.png, it will look for it in /styles/img/JaxonsBlack.png.
因此,如果您的/ css文件位于/styles/blah.css中,并且具有url img / JaxonsBlack.png,它将在/styles/img/JaxonsBlack.png中查找它。 If this is the case you can fix it by changing it to /img/JaxonsBlack.png.
如果是这种情况,您可以通过将其更改为/img/JaxonsBlack.png进行修复。 As others have mentioned, the div will not have a vertical height unless it has content, or you define one.
正如其他人提到的那样,除非有内容或您定义一个div,否则div不会具有垂直高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.