是否可以在 CSS 中设置 img 标签的 src 属性的等效项? [英] Is it possible to set the equivalent of a src attribute of an img tag in CSS?
本文介绍了是否可以在 CSS 中设置 img 标签的 src 属性的等效项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 CSS 中设置 src
属性值?目前,我在做的是:
Is it possible to set the src
attribute value in CSS? At present, what I am doing is:
<img src="pathTo/myImage.jpg"/>
我希望它是这样的
<img class="myClass"/>
.myClass {
some-src-property: url("pathTo/myImage.jpg");
我想不使用 CSS 中的 background
或 background-image:
属性来执行此操作.
I want to do this without using the background
or background-image:
properties in CSS.
推荐答案
完整的解决方案(现场演示):
Full working solution (Live Demo):
<!doctype html>
<style>
.MyClass123{
content:url("http://imgur.com/SZ8Cm.jpg");
}
</style>
<img class="MyClass123"/>
测试和工作:
- Chrome 14.0.835.163
- Safari 4.0.5
- 歌剧 10.6
经过测试且无效:
- FireFox 40.0.2(观察开发者网络工具,可以看到加载了网址,但没有显示图片)
- Internet Explorer 11.0.9600.17905(URL 从不加载)
这篇关于是否可以在 CSS 中设置 img 标签的 src 属性的等效项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文