Bootstrap 4卡页脚与页面底部对齐

时间:2018-08-16 12:48:30

标签: html css bootstrap-4

我正在使用Bootsrap 4卡的'card-footer'类,但是页脚未与页面底部对齐。

这里是链接to the js fiddle

<div class="container">
   <div class="card text-center">
     <div class="card-header">Featured</div>
     <div class="card-body">
       <h5 class="card-title">Special title treatment</h5>
       <p class="card-text">This text should be equi-distance from header 
       and footer. </p>
       <p class="card-text">
       Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam 
       sapien sem, ornare ac, nonummy non, lobortis a enim. Nam sed 
       tellus id magna elementum tincidunt. Pellentesque habitant morbi 
       tristique senectus et netus et malesuada fames ac turpis egestas. 
       Aliquam ornare wisi eu metus. In enim a arcu imperdiet malesuada. 
       Nam quis nulla. Vivamus luctus egestas leo. 
       </p>
   </div>
   <div class="card-footer text-muted">
    This footer should be at the bottom
  </div>
 </div>
</div>

3 个答案:

答案 0 :(得分:4)

卡片必须全高。 Bootstrap 4具有h-100 ...的height:100%类...

<div class="container h-100">
<div class="card h-100 text-center">
  <div class="card-header">
    Featured
  </div>
  <div class="card-body">
    <h5 class="card-title">Special title treatment</h5>
    ...
  </div>
  <div class="card-footer text-muted">
    This footer should be at the bottom
  </div>
</div>
</div>

https://jsfiddle.net/eqfxk9wo/

答案 1 :(得分:1)

我认为最简单的方法是给卡片页脚一个 mt-auto 类

  <div class="card-footer mt-auto" >
    Whatever
  </div>

答案 2 :(得分:0)

我个人会从头开始创建自己的页脚,但是可以使用以下方法将其与底部对齐:将以下内容添加到CSS:

.card {
    height: 100vh;
}