gpt4 book ai didi

html - Angular Bootstrap Carousel - 在不拉伸(stretch)的情况下使图像适合方框

转载 作者:行者123 更新时间:2023-11-28 17:29:47 27 4
gpt4 key购买 nike

我有一个带有多张图片的 Angular 旋转木马,所有图片的大小都不相同,纵横比也不相同,我怎样才能让图片填充一个黑色方框,比如 250x250 像素而不拉伸(stretch)它们?即风景图像将在顶部和底部有黑条,肖像将在左侧和右侧有黑条。

最佳答案

尝试像这样使用 max-widthmax-height:

figure {
width: 250px;
height: 250px;
background-color: #000;
text-align: center;
display: table-cell;
vertical-align: middle;
}

img {
max-width: 100%;
max-height: 100%;
}
<figure>
<img src="http://lorempixel.com/250/150">
</figure>

关于html - Angular Bootstrap Carousel - 在不拉伸(stretch)的情况下使图像适合方框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26363914/

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