我试图弄清楚如何object-fit
正确缩放 16:9 垂直图像。
我几乎没有运气尝试过任何事情!
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>
预期结果(不使用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>
我希望我可以object-fit
改用。对这种方法的想法?