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?
When you need to center an image inside a <div> tag, you can apply the text-align:center CSS property to the <div> tag. Then, you need to add the class into the <div> tag that contains the <img> tag.
To insert an image in HTML, use the image tag and include a source and alt attribute. Like any other HTML element, you'll add images to the body section of your HTML file. The HTML image element is an “empty element,” meaning it does not have a closing tag.
To add images to a page, we use the <img> inline element. The <img> element is a self-containing, or empty, element, which means that it doesn't wrap any other content and it exists as a single tag. For the <img> element to work, a src attribute and value must be included to specify the source of the image.
This answer by Jaap :
<div class="image"></div>
and in CSS :
div.image::before { 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)
you can do this:
<div class="picture1"> </div>
and put this into your css file:
div.picture1 { width:100px; /*width of your image*/ height:100px; /*height of your image*/ background-image:url('yourimage.file'); margin:0; /* If you want no margin */ padding:0; /*if your want to padding */ }
otherwise, just use them as plain
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With