I know I'm two years late, but what about the practice suggested here ?
<div class="embed-container ratio-16-9"> <img src="imgage.jpg"/> </div> .embed-container { position: relative; height: 0; overflow: hidden; background-color:black; } .ratio-16-9{ padding-bottom:56.25%; } .ratio-4-3{ padding-bottom:75%; } .ratio-1-1{ padding-bottom:100%;
In addition, an important note from the comments section to which you should pay attention, and improve the original technique:
Good trick. However, if I were you, I would replace the "img" tag with a background image on your div (and background-size: cover or contains). This avoids the position trick, the overflow trick, and a lot of work for the browser.
I hope someone finds this helpful.
pilau source share