我正在使用这样的 css 设置图像的 src
#Banner {
content: url(../Banners/prussia-awesomeness.gif);
width: 1000px;
}
这是我的图片
<div id="Header" class="Header">
<img id="Banner" src="as"/>
</div>
图像使用正确的 img src 在 google chrome 中加载 (../Banners/prusia-awesomeness.gif)
在 Internet Explorer 和 Firefox 中,它将 src 保持为“as”。
ie和ff不支持从css加载图片源吗?
EDIT:
adding
#Banner:after {
content: url(../Banners/prussia-awesomeness.gif);
width: 1000px;
}
使它在 Firefox 中工作,但 ie 仍然拒绝合作。
还尝试添加 :before (使用 : 和 ::),这在任何浏览器中都没有区别
CSS 内容属性似乎不适用于 IMG,但适用于 IE 和 Safari 的其他元素。查看this http://jsfiddle.net/Y3TYZ/1/小提琴。对于 Safari 检查this https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-content out.
HTML:
<div id="Header" class="Header">
<img id="Banner1" src="as"/>
<h1 id="Banner">test</h1>
</div>
CSS:
#Banner:before {
content: url(http://w3c.org/2008/site/images/favicon.ico);
width: 1000px;
}
#Banner1:before {
content: url(http://w3c.org/2008/site/images/favicon.ico);
width: 1000px;
}
如果您没有 DOCTYPE,它可能无法在 IE8 上运行!指定的。
对于 FF,您需要使用 :before 或 :after 伪元素才能使其工作。欲了解更多信息,请通过this https://developer.mozilla.org/en-US/docs/Web/CSS/content.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)