问题描述
我使用css设置图像的src,如下所示
#Banner {
content:url (../Banners/prussia-awesomeness.gif);
width:1000px;
}
这是我的形象
< div id =Headerclass =Header>
< img id =Bannersrc =as/>
< / div>
图片会加载到google chrome中,并加上适当的img src(../Banners/prussia-awesomeness。 gif)
在互联网浏览器和firefox它保持srcas。
支持从css加载图片来源?
编辑:
添加
#Banner:after {
content:url(../ Banners / prussia-awesomeness.gif);
width:1000px;
}
使其在firefox中正常工作,但仍然拒绝协作。 >
也尝试添加:before(with:and::),在任何浏览器中都没有任何区别
看来CSS内容属性不适用于IMG,但其他元素的IE&苹果浏览器。请查看小提琴。对于Safari检查。
HTML :
< div id =Headerclass =Header>
< img id =Banner1src =as/>
< h1 id =Banner>测试< / 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伪元素使其工作。有关详情,请访问。
I'm setting the src for an image with css like this
#Banner {
content: url(../Banners/prussia-awesomeness.gif);
width: 1000px;
}
here's my image
<div id="Header" class="Header">
<img id="Banner" src="as"/>
</div>
the image loads in google chrome with the proper img src (../Banners/prussia-awesomeness.gif)
in internet explorer and firefox it keeps the src "as".
Does ie and ff not support loading image sources from css?
EDIT:
adding
#Banner:after {
content: url(../Banners/prussia-awesomeness.gif);
width: 1000px;
}
made it work in firefox, ie however still refuses to cooperate.
also tried adding :before (with : and ::), which made no difference in any browser
It seems that CSS content property doesn't work for IMG but other elements for IE & Safari. Check out this Fiddle. For Safari check this 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;
}
It may not work with IE8 if you don't have DOCTYPE! specified.
For FF you need to use :before or :after pseudo elements to make it work. For more info go through this.
这篇关于FF和IE不从CSS加载img src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!