gpt4 book ai didi

html - CSS 图像按高度调整大小

转载 作者:行者123 更新时间:2023-11-28 00:01:37 25 4
gpt4 key购买 nike

我知道根据宽度改变图像比例的图像大小调整技术:

img{
max-width: 100%;
height: auto;
}

我只需要根据父级的高度而不是宽度来做同样的事情。我试过以下没有效果:

img{
width: auto;
max-height: 100%;
}

我希望我解释得足够好。

请帮忙:)

最佳答案

max-height 只会限制高度小于给定值。

如果你想让它和它的父级一样..给它height: 100%

因此这应该有效:CSS:

img{
height: 100%; // changed max-height to height here
width: auto; // this is optional
}

关于html - CSS 图像按高度调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21029709/

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