如何把图像放在div的CSS? [英] How to put an image in div with CSS?

查看:181
本文介绍了如何把图像放在div的CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把所有我的图片在CSS(我知道如何将它们作为背景图片的唯一方式)。



但在这个问题解决方案是你永远不能让div占据图像的大小。



所以我的问题是:什么是最好的方式有等价的
< div>< img src =.../>< / div>

h2_lin>解决方案

Jaap 的回答:

 < div class =image>< / div> 

和CSS中:

  div.image {
content:url http://placehold.it/350x150);
}

您可以在此链接上尝试:
http://jsfiddle.net/XAh2d/



这是一个关于css内容的链接
http://css-tricks.com/css-content/



这已经过Chrome,firefox和Safari的测试。 (我在mac上,所以如果有人在IE上有结果,请告诉我添加它)


I would like to have all my images in CSS (the only way I know how is to put them in as background images).

But the problem in this solution is you can never let the div take the size of the image.

So my question is: what is the best way to have the equivalent of <div><img src="..." /></div> in CSS?

解决方案

This answer by Jaap :

<div class="image"></div>​

and in CSS :

div.image {
   content:url(http://placehold.it/350x150);
}​

you can try it on this link : http://jsfiddle.net/XAh2d/

this is a link about css content http://css-tricks.com/css-content/

This has been tested on Chrome, firefox and Safari. (I'm on a mac, so if someone has the result on IE, tell me to add it)

这篇关于如何把图像放在div的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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