gpt4 book ai didi

html - Bootstrap 中的全高并排图像

转载 作者:太空宇宙 更新时间:2023-11-04 08:39:21 26 4
gpt4 key购买 nike

我想获得下图所示的结构。将有一个全宽和全高的容器,其中包含 2 张图像和其他元素。我的图像应该是全高(容器的高度)和容器内的自动宽度(分别从中心向左增长,向右增长)。我的问题是我的图像比容器高得多,我需要以某种方式将它们限制在容器内(红色区域)以填充它的整个高度。 desired structurePS.1 所有图片均为纵向模式,所有图片高度相同。PS.2 我看了看 Stack 上的其他问题。PS.3 你得到了here我的非工作示例。

欢迎提出任何建议。谢谢!

最佳答案

您可以为您想要的结果定义 flex 。 'justify-content' as center 将使您的图像居中,两边的边距相等。

附言。如果您希望覆盖整个 div,请为图片添加 50% 的宽度。

.container {
width: 100%;
background: lightgrey;
height: 300px;
padding-top: 10px;
padding-bottom: 10px;
}

.child {
display: flex;
width: 100%;
justify-content: center;
height: inherit;
}

#img1,
#img2 {
height: 100%;
align-items: stretch;
}
<div class="container">

<div class="child">

<img src="https://s-media-cache-ak0.pinimg.com/736x/36/66/76/3666764312573a54adef888747d0c8f3.jpg" id="img1">


<img src="https://s-media-cache-ak0.pinimg.com/736x/64/07/19/640719d42a8107720d760349fcfbbd52.jpg" id="img2">

</div>

</div>

关于html - Bootstrap 中的全高并排图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44248748/

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