I have a slideshow sort of thing where images will expand as large as they can, but not exceed the viewport\'s width or height. Basically object-fit: contain
.
I think I got it (1/2) is equal to (width/height):
<img
srcset="http://lorempixel.com/960/1920/sports/10/w1920/ 960w"
sizes="(min-aspect-ratio: 1/2) calc(100vh * (1 / 2))"
/>
Or with more code:
<img
srcset="http://lorempixel.com/960/1920/sports/10/w1920/ 960w"
sizes="(min-aspect-ratio: 1/2) calc(100vh * (1 / 2)), 100vw"
/>
As a side note: I also have written a script that automatically calculates the right sizes for parent height/width constrained sizes. See here the parent-fit script.