0

我正在使用 bootstrap 4 来显示卡片。一切都按预期工作。我遇到的问题是,如果其中一个页脚的内容比其他页脚多,则会提高页脚以适应这一点。有没有一种方法可以让页脚向下推动内容并保持顶部对齐?

演示:http: //jsfiddle.net/6uv9a30n/1/

<div class="container">
  <div class="card-deck">
    <div class="card mb-4">
      <div class="card-body">
        <h4 class="card-title">1 Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer">
        <small class="text-muted">Last updated 3 mins ago</small>
      </div>
    </div>
 </div>
</div>

电流输出: 在此处输入图像描述

期望的输出: 在此处输入图像描述

4

2 回答 2

0

您可以使用 和 上的 CSS 属性来做到这flex一点。card-bodycard-footer

body {
  margin: 10px;
}

/* Customize Bootstrap card */
.card-deck .card-body { 
  flex: 0 0 auto;
}

/* fix footer height */
.card-footer { 
  flex: 1;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" >

<div class="container">
  <div class="card-deck">
    <div class="card mb-4">
      <div class="card-body">
        <h4 class="card-title">1 Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer equal">
        <small class="text-muted">Last updated 3 mins ago</small>
      </div>
    </div>
    <div class="card mb-4">
      <div class="card-body">
        <h4 class="card-title">1 Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer">
        <small class="text-muted">Last updated 3 mins ago Last updated 3 mins ago</small>
      </div>
    </div>
    <div class="card mb-4">
      <div class="card-body">
        <h4 class="card-title">1 Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer">
        <small class="text-muted">Last updated 3 mins ago</small>
      </div>
    </div>
  </div>
</div>

于 2020-06-12T12:28:22.470 回答
0

这听起来很便宜,但是您可以使用另一个具有属性颜色的smallHTML 标记,这样无论您添加多少文本,它都会始终保持在顶部。csstransparent

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">



<div class="container">
  <div class="card-deck">
    <div class="card mb-4">
      <div class="card-body">
        <h4 class="card-title">1 Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer">
        <small class="text-muted">Last updated 3 mins ago</small>
        <small style="color: transparent;">Text not going to show</small>
      </div>
    </div>
    <div class="card mb-4">
      <div class="card-body">
        <h4 class="card-title">1 Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer">
        <small class="text-muted">Last updated 3 mins ago Last updated 3 mins ago</small>

      </div>
    </div>
    <div class="card mb-4">
      <div class="card-body">
        <h4 class="card-title">1 Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer">
        <small class="text-muted">Last updated 3 mins ago</small>
        <small style="color: transparent;">Text not going to show</small>
      </div>
    </div>
  </div>
</div>

于 2020-06-12T08:33:43.023 回答