如何在Bootstrap 4中使每一列的高度相等?

时间:2019-02-12 19:59:30

标签: html css bootstrap-4

看看这张照片:

enter image description here

第二列在右边,看起来高度不等于第一列,我需要弄清楚第二列应如何获得与第一列相同的高度。

我的HTML:

<div class="row"">
  <div class="col-8">
    <div class="row">
      <div class="col-12 mb-2">
        <div class="imgcontainer">
          <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
          <div class="top-left">Top Left</div>
        </div>
      </div>
      <div class="col-12">
        <div class="imgcontainer">
          <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
          <div class="top-left">Top Left</div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-4">
    <div class="row">
      <div class="col-12">
        <div class="imgcontainer">
          <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
          <div class="top-left">Top Left</div>
        </div>
      </div>
      <div class="col-12">
        <div class="imgcontainer">
          <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
          <div class="top-left">Top Left</div>
        </div>
      </div>
      <div class="col-12">
        <div class="imgcontainer">
          <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
          <div class="top-left">Top Left</div>
        </div>
      </div>
    </div>
  </div>
</div>

2 个答案:

答案 0 :(得分:2)

使用flexbox实用工具在右栏display:flex, flex-direction: column ...

<div class="container-fluid">
    <div class="row">
        <div class="col-8">
            <div class="row">
                <div class="col-12 mb-2">
                    <div class="imgcontainer">
                        <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
                        <div class="top-left">Top Left</div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="imgcontainer">
                        <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
                        <div class="top-left">Top Left</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-4 d-flex flex-column">
            <div class="row flex-fill justify-content-between">
                <div class="col-12">
                    <div class="imgcontainer">
                        <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
                        <div class="top-left">Top Left</div>
                    </div>
                </div>
                <div class="col-12">
                    <div class="imgcontainer">
                        <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
                        <div class="top-left">Top Left</div>
                    </div>
                </div>
                <div class="col-12 d-flex align-items-end">
                    <div class="imgcontainer">
                        <img src="https://loremflickr.com/1280/720" class="img-fluid" alt="Picture">
                        <div class="top-left">Top Left</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

https://www.codeply.com/go/hlHhjz3K1Q

答案 1 :(得分:1)

您可以尝试以下操作:

enter image description here

<div class="container">
  <div class="d-md-flex">
    <div class="flex flex-row flex-nowrap">
      <img src="https://i.imgur.com/exWWySt.png">
      <img src="https://i.imgur.com/exWWySt.png">
    </div>

    <div class="flex-column">
      <img src="https://i.imgur.com/exWWySt.png" height="300">
      <img src="https://i.imgur.com/exWWySt.png" height="300">
      <img src="https://i.imgur.com/exWWySt.png" height="300">
    </div>
  </div>
</div>

Codepen