bootstrap 4卡-具有可变标题行的垂直对齐正文

时间:2018-08-15 14:20:02

标签: html css bootstrap-4 alignment

在我的简单设计中,我使用卡片展示一些产品。但是,某些产品标题包含2行,而其他产品仅包含1行。

我想使正文文本垂直对齐(还有价格按钮)。

<div class="container">
      <div class="row">
        <div class="col-12">
            <div class="card-group">
                <div class="card text-center" >
                        <img class="card-img-top mx-auto d-block" style="max-width: 100%; max-height: 100%;object-fit: scale-down" src="http://s.s-bol.com/imgbase0/imagebase3/thumb/FC/1/4/7/9/9200000037279741.jpg"  height="200px" alt="Card image cap">
                        <div class="card-body">
                          <h5 class="card-title">AKRACING Nitro Gaming Racestoel - Wit</h5>
                          <p class="card-body">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="btn btn-danger">€ 279,-</a>
                        </div>
                </div>
                <div class="card text-center" >
                        <img class="card-img-top mx-auto d-block" style="max-width: 100%; max-height: 100%;object-fit: scale-down" src="http://s.s-bol.com/imgbase0/imagebase3/thumb/FC/2/4/2/4/9200000076564242.jpg" height="200px" width="25%" alt="Card image cap">
                        <div class="card-body">
                          <h5 class="card-title">MSI Gaming GS Rugzak</h5>
                          <p class="card-body">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="btn btn-danger">€ 151,-</a>
                        </div>
                </div>
                <div class="card text-center" >
                        <img  class="card-img-top mx-auto d-block" style="max-width: 100%; max-height: 100%;object-fit: scale-down" src="http://s.s-bol.com/imgbase0/imagebase3/thumb/FC/3/2/4/9/9200000088829423.jpg"  height="200px" alt="Card image cap">
                        <div class="card-body">
                          <h5 class="card-title">DJI Mavic Air Onyx Zwart - Drone</h5>
                          <p class="card-body">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="btn btn-danger">€ 753,91</a>
                        </div>
                </div>
                <div class="card text-center" >
                        <img class="card-img-top mx-auto d-block" style="max-width: 100%; max-height: 100%;object-fit: scale-down" src="http://s.s-bol.com/imgbase0/imagebase3/thumb/FC/1/7/0/9/9200000063589071.jpg"  height="200px" alt="Card image cap">
                        <div class="card-body">
                          <h5 class="card-title">BenQ TH683 - Full HD Beamer</h5>
                          <p class="card-body">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="btn btn-danger">€ 589,-</a>
                        </div>
                </div>

            </div>
        </div>
          </div>

</div>

工作代码段可以在这里找到:https://www.codeply.com/go/zzm764UnFU

edit 添加的代码也内联

1 个答案:

答案 0 :(得分:2)

正如@Paulie_D所提到的,实际上没有简单的方法可以在卡片中对齐项目,因为这些项目具有不同的父卡片。

最好的办法是将按钮和说明按到底部(使用render),以使按钮与底部对齐...

mt-auto

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