With CSS you can simulate object-fit: [cover|contain];
. It's use transform
and [max|min]-[width|height]
.
It's not perfect. That not work in one case: if the image is wider and shorter than the container.
.img-ctr{_x000D_
background: red;/*visible only in contain mode*/_x000D_
border: 1px solid black;_x000D_
height: 300px;_x000D_
width: 600px;_x000D_
overflow: hidden;_x000D_
position: relative;_x000D_
display: block;_x000D_
}_x000D_
.img{_x000D_
display: block;_x000D_
_x000D_
/*contain:*/_x000D_
/*max-height: 100%;_x000D_
max-width: 100%;*/_x000D_
/*--*/_x000D_
_x000D_
/*cover (not work for images wider and shorter than the container):*/_x000D_
min-height: 100%;_x000D_
width: 100%;_x000D_
/*--*/_x000D_
_x000D_
position: absolute;_x000D_
top: 50%;_x000D_
left: 50%;_x000D_
transform: translate(-50%, -50%);_x000D_
}
_x000D_
<p>Large square:_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/1000x1000"></span>_x000D_
</p>_x000D_
<p>Small square:_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/100x100"></span>_x000D_
</p>_x000D_
<p>Large landscape:_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/2000x1000"></span>_x000D_
</p>_x000D_
<p>Small landscape:_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/200x100"></span>_x000D_
</p>_x000D_
<p>Large portrait:_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/1000x2000"></span>_x000D_
</p>_x000D_
<p>Small portrait:_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/100x200"></span>_x000D_
</p>_x000D_
<p>Ultra thin portrait:_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/200x1000"></span>_x000D_
</p>_x000D_
<p>Ultra wide landscape (images wider and shorter than the container):_x000D_
<span class="img-ctr"><img class="img" src="http://placehold.it/1000x200"></span>_x000D_
</p>
_x000D_