JSFiddle - React, Tailwind, and code Playground
by calder12
HTML
<div class="one">
<img src="https://placeimg.com/300/375/any">
</div>
<div class="one">
<img src="https://placeimg.com/300/240/any">
</div>
CSS
.one {
width: 300px;
height: 240px;
overflow: hidden;
}
JavaScript
$(document).ready(function() {
$('.one img').each( function() {
if( $(this).height() > 240 ) {
var diff = ($(this).height() - 240) /2
$(this).css('margin-top', (diff * -1) + 'px')
}
})
})