<div class="newsBlocks"></div>
css:
.newsBlocks{
background: url(../img/news/1.png);
}
How to set my div to the size of 1.png?
<div class="newsBlocks"></div>
css:
.newsBlocks{
background: url(../img/news/1.png);
}
How to set my div to the size of 1.png?
It's not possible to auto-size a div based on the size of it's background image, but you could do it this very (hacky) way, by including an img
tag with the url to the image, setting the img
to visibility:hidden;
[used inline CSS for brevity - don't kill me!]:
<div style="background-image: url('img.jpg');">
<img src="img.jpg" style="visibility:hidden"/>
</div
You can do it statically by manually setting the CSS of the div to the height and width of the image, otherwise you can do it dynamically by using Javascript to get the height and width of the background image as detailed here: Get the Size of a CSS Background Image Using JavaScript?