gpt4 book ai didi

css - 避免在图像 CSS 上拉伸(stretch)

转载 作者:技术小花猫 更新时间:2023-10-29 10:55:31 25 4
gpt4 key购买 nike

我正在将图像渲染到 div 中。我想避免拉伸(stretch)图像。

div {
height: 300px;
width: 300px;
}
img {
min-width: 300px;
min-height: 300px;
max-height: 300px;
}

我的问题是图像的宽度会拉伸(stretch)。我希望它具有常规宽度,即使部分图像会丢失。

div {
height: 300px;
width: 300px;
overflow: hidden;
}
img {
height: 300px
max-width: none;
min-width: 300px;
}

最佳答案

您只需添加 object-fit: cover; 即可实现此目的。一个例子可能是 -

img {
height: 300px
width: 100%;
object-fit: cover;
}

关于css - 避免在图像 CSS 上拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16177707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com