【发布时间】:2018-12-04 20:03:01
【问题描述】:
我正在尝试确定object-fit: contain; 在仅提供宽度百分比时是否可以处理多个图像。我希望所有<img> 相对于纵横比都具有相同的可视高度,并认为给出max-width: 5%; 会强制隐含高度。我愿意使用flexbox,尽管当我尝试使用它时,我最终遇到了同样的问题。在下面,第二张li 图片(“curry_2.jpg”)缩小了,但不正确。
div.imgbox {
width: 100%
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
ul li {
float: left;
max-width: 5%;
height: 100%;
}
ul li img {
width: 100%;
height: 100%;
object-fit: contain;
<div class="imgbox">
<ul class="imgs">
<li><img src="https://web.archive.org/web/20010806195135im_/http://rubberburner.com:80/curry_1.jpg"></li>
<li><img src="https://web.archive.org/web/20010806195628im_/http://rubberburner.com:80/curry_2.jpg"></li>
<!-- The above image, "curry_2.jpg" shrinks but not correctly -->
<li><img src="https://web.archive.org/web/20010806194159im_/http://rubberburner.com:80/all_curry1.jpg"></li>
</ul>
</div>
编辑
我不知道为什么,但是使用height: vw 可以按照我想要的方式工作,保持行稳定。 height: vh 也可以工作,但这允许图像在页面调整大小时翻滚,从而显示为多行。
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
ul li {
float: left;
height: 10vw; /* height using vW... not vH? */
}
.imgs img {
max-height: 100%;
object-fit: contain;
}
<div class="imgbox">
<ul class="imgs">
<li><img src="https://web.archive.org/web/20010806195135im_/http://rubberburner.com:80/curry_1.jpg"></li>
<li><img src="https://web.archive.org/web/20010806195628im_/http://rubberburner.com:80/curry_2.jpg"></li>
<!-- The above image, "curry_2.jpg" shrinks -->
<li><img src="https://web.archive.org/web/20010806194159im_/http://rubberburner.com:80/all_curry1.jpg"></li>
</ul>
</div>
【问题讨论】: