html - Bootstrap 中的全高并排图像

标签 html css twitter-bootstrap

我想获得下图所示的结构。将有一个全宽和全高的容器,其中包含 2 张图像和其他元素。我的图像应该是全高(容器的高度)和容器内的自动宽度(分别从中心向左增长,向右增长)。我的问题是我的图像比容器高得多,我需要以某种方式将它们限制在容器内(红色区域)以填充它的整个高度。 desired structure PS.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/

相关文章:

python - 将数据从 Django View 传递到 D3

javascript - 基于多个无序列表选择显示/隐藏表格

javascript - 单击此 html 层次结构的链接显示特定的 div

java - Android:我怎么知道CSS注入(inject)完成了?

javascript - 如何定义CSS :hover state in a jQuery selector?

jquery - 动态添加和删除 Bootstrap 提前输入

html - 如何为多个不重叠的外部和内部 div 添加线条边框

javascript - 用 javascript 更改 css 不起作用

html - 导航链接不适用于 z-index

javascript - Bootstrap 弹出窗口/点击