css - Bootstrap 列内的响应图像高度

标签 css twitter-bootstrap bootstrap-4

我不知道为什么这是这样一场斗争。我想将图像放入容器中。该图像应该是响应式的,这意味着当列的宽度变小时,图像也应该变小。它现在这样做了,但它保持了高度,这意味着它看起来会被拉长。

https://codepen.io/anon/pen/vmZKyM

<div class="container-fluid">
  <div class="col-md-8 offset-md-2">
    <div class="row">
      <div class="col-md-4 offset-md-2">
        <div class="row">
          <p>Left column</p>
          <img src="http://placehold.it/600x400" />
        </div>
      </div>
      <div class="col-md-5 offset-md-1">
        <div class="row">
          <p>Right column</p>
          <img src="http://placehold.it/700x400" />
        </div>
      </div>
    </div>
  </div>
</div>

我不知道图像的宽高比(在本例中我知道),所以我无法使用 padding-bottom 技巧(通常用于图像)实现这一点。

我怎样才能做到这一点?

最佳答案

max-width: 100%; 更改为 width: 100%; 同时将 height: auto; 更改为 height: 100%;

关于css - Bootstrap 列内的响应图像高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732627/

相关文章:

html - Bootstrap4 - 使用剪辑路径属性时不显示菜单下拉菜单

html - 背景重复-y 但不在页面下方

javascript - JQuery、Bootstrap navs - 如何添加上一个/下一个按钮?

css - 如何使引导容器在 gutenburg alignfull 中工作

css - 在 Bootstrap 中制作更小的按钮

html - 用于 span 标签的 Twitter Bootstrap 工具提示(不适用于标签)

每行中的PHP bootstrap 4模态删除按钮

html - 通用基于用户的宽度

javascript - 如果 Else CSS Hovercode 在 jQuery 中不起作用

css - 如何使用Parcel从@ font-face加载字体?