3 ms·
I do this in production a few places by setting a div with no content or only absolutely position content to have padding-bottom of the aspect ratio in %. That
by whelming_wave 7y ago
I do this in production a few places by setting a div with no content or only absolutely position content to have padding-bottom of the aspect ratio in %. That gets calculated from the width, so if the image is 4:3 my ratio is 75%; 200px wide becomes 150px tall as well. Then, I set the image as a background to the div or absolutely position it inside to fill the space, and it's responsive to the layout while also reserving space for itself.