JSFiddle - React, Tailwind, and code Playground
by Will Mo
HTML
<h2>Cropped</h2>
<h3>CSS</h3>
<div class="css" style="background-image: url(https://i.imgur.com/krcUjZf.jpg);">
</div>
<h3>img tag</h3>
<div>
<img src="https://i.imgur.com/krcUjZf.jpg" />
</div>
<h2>Original</h2>
<img src="https://i.imgur.com/krcUjZf.jpg" />
CSS
div {
height: 150px;
overflow: hidden;
border: 1px solid #ccc;
}
img {
height: auto;
width: 100%;
}
div > img {
margin-top: -50%; /* iffy! */
}
div.css {
background-position: 50% 50%;
/* if you need to stretch it, uncomment this: */
background-size: 100% auto;
}