I'm trying to figure out how to use object-fit
to properly scale a 16:9 vertical image.
I've tried almost anything with no luck!
https://jsfiddle.net/pdocys3j/
.container {
width: 300px; /*any size*/
height: 200px; /*any size*/
}
.object-fit-cover {
width: 100%;
height: 100%;
object-fit: cover; /*magic*/
}
<div class="container">
<img class="object-fit-cover" src="https://jardim-plant-images-development.s3.amazonaws.com/hfj1h9jq2q8o8tyv1r6dxhi4zrmn">
</div>
The expected result (without using object-fit
:
.container {
width: 300px; /*any size*/
height: 200px; /*any size*/
overflow: hidden;
}
.object-fit-cover {
width: 100%;
margin-top: -50%;
}
<div class="container">
<img class="object-fit-cover" src="https://jardim-plant-images-development.s3.amazonaws.com/hfj1h9jq2q8o8tyv1r6dxhi4zrmn">
</div>
I am hoping that I could use object-fit
instead. Thoughts on this approach?