html
<div>
<img src="http://www.hdwallpapersplus.com/wp-content/uploads/2013/06/abstract_color_background_picture_8016-wide.jpg" />
</div>
css
div{
width: 200px;
height: 100px;
background-color: red;
}
img{
position: relative;
width: 100%;
height: 100%;
background-size: cover;
}
Why isn't the background-size: cover property working in this scenario? It should be supported in CSS3, but it's not having an effect. Is there a way to prevent the image from stretching?
We can achieve a similar effect using
background: url("http://www.hdwallpapersplus.com/wp-content/uploads/2013/06/abstract_color_background_picture_8016-wide.jpg") no-repeat; background-size: cover;
instead.