是否可以在CSS中设置img标签的src属性的等价物? [英] Is it possible to set the equivalent of a src attribute of an img tag in CSS?

查看:191
本文介绍了是否可以在CSS中设置img标签的src属性的等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在CSS中设置 src 属性值?目前,我在做什么是

 < img src =pathTo / myImage.jpg/> 

我希望它是这样的

 < img class =myClass/> 



  .myClass {
some-src-property:url(pathTo / myImage.jpg);

我想这样做没有使用背景

解决方案 div>

使用 content:url(image.jpg)

$



全功能解决方案( 演示 ):



 <!doctype html>< style> .MyClass123 {content :url(http://imgur.com/SZ8Cm.jpg);}< / style>< img class =MyClass123/>  

/ div>



测试并正常运行:




  • Chrome 14.0 .835.163

  • Safari 4.0.5

  • Opera 10.6



测试并




  • FireFox 40.0.2(观察开发人员网络工具,

  • Internet Explorer 11.0.9600.17905(网址从不加载)


Is it possible to set the src attribute value in CSS? At present, what iI am doing is:

<img src="pathTo/myImage.jpg"/>

and I want it to be something like this

<img class="myClass" />

.myClass {
    some-src-property: url("pathTo/myImage.jpg");

I want to do this without using the background or background-image: properties in CSS.

解决方案

Use content:url("image.jpg").

Full working solution (Live Demo):

<!doctype html>

<style>
.MyClass123{
	content:url("http://imgur.com/SZ8Cm.jpg");
}
</style>

<img class="MyClass123"/>

Tested and working:

  • Chrome 14.0.835.163
  • Safari 4.0.5
  • Opera 10.6

Tested and Not working:

  • FireFox 40.0.2 (observing Developer Network Tools, you can see that the URL loads, but the image is not displayed)
  • Internet Explorer 11.0.9600.17905 (URL never loads)

这篇关于是否可以在CSS中设置img标签的src属性的等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆