【发布时间】:2017-06-21 02:55:46
【问题描述】:
- 1 行,里面有 3 张图片。
- 1 行,里面有 2 张图片。
如何使 100%-width-container 中的图像具有相同的高度?
所有图片都没有一致的宽度和高度。 我需要图像来保持它们的裁剪和纵横比。 它们不需要具有相同的宽度。
到目前为止,这是我使用 flex-box 取得的成果。但它们的高度不同。我不介意使用 JavaScript 来解决这个问题。
我宁愿不为容器或图像设置高度值。 有没有办法让图像在具有相同高度的同时均匀分布?
.wrapper {
width:100vw; /*should be width of browser*/
display:flex;
margin:0;
padding:0;
margin:0;
border:1px solid;
}
.image {
list-style:none;
margin: 50px 1.5%;
}
.image:first-child {
margin-left:0;
}
.image:last-child {
margin-right:0;
}
img {
width:100%
}
<ul class="wrapper three_images">
<li class="image"><img src="http://lorempixel.com/600/800/"></li>
<li class="image"><img src="http://lorempixel.com/400/850/"></li>
<li class="image"><img src="http://lorempixel.com/550/700/"></li>
</ul>
<ul class="wrapper two_images">
<li class="image"><img src="http://lorempixel.com/600/800/"></li>
<li class="image"><img src="http://lorempixel.com/400/850/"></li>
</ul>
【问题讨论】:
-
基本上,您不能在不扭曲图像的情况下对 inline 图像执行此操作。
-
有什么替代内嵌图片的方法?
-
如果图片的高度不同,应该缩放哪个图片?
标签: javascript html css flexbox