【问题标题】:How can I make a card deck with fixed-width cards?如何用固定宽度的卡片制作卡片组?
【发布时间】:2018-07-15 07:52:42
【问题描述】:

我想使用 Bootstrap 4 fixed-width cards 做出响应式 card deck。在这里,我发布了下面的代码,但它没有响应。为什么?

<div class="card-deck">
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
    <div class="card-body">
        <h4 class="card-title">Title 1</h4>
        <p>Small text here</p>
        <small class="text-muted">3 mins ago</small>
    </div>
</div>
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
    <div class="card-body">
        <h4 class="card-title">Title 2</h4>
        <p>Small text here</p>
        <small class="text-muted">3 mins ago</small>
    </div>
</div>
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
    <div class="card-body">
        <h4 class="card-title">Title 3</h4>
        <p>Small text here</p>
        <small class="text-muted">3 mins ago</small>
    </div>
</div>
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
    <div class="card-body">
        <h4 class="card-title">Title 4</h4>
        <p>Small text here</p>
        <small class="text-muted">3 mins ago</small>
    </div>
</div>

【问题讨论】:

  • 在减少视口时,因为没有一一中断,所以没有响应

标签: html css twitter-bootstrap bootstrap-4


【解决方案1】:

Deck 使卡片高度相等。

添加行删除牌组是正确的。添加 col-lg-3 col-md-2 col-sm-12 将在手机上提供一个四卡桌面等。

使用最大数字的高度设置高度,使“OK”看起来很直。

【讨论】:

    【解决方案2】:

    here 中提到,这些布局选项还没有响应。所以我找到了一个简单的解决方案。将父 &lt;div class="card-deck"&gt;...&lt;/div&gt; 更改为 &lt;div class="row"&gt;...&lt;/div&gt;

    【讨论】:

      【解决方案3】:

      对于带有 固定宽度 卡片的 Bootstrap 4 卡片组,请执行以下操作:

      将每张卡片放入具有 col-auto mb-3 类的列中(自动宽度列 + 底部边距,三个单位)。

      要将它们居中,请将justify-content-center 类添加到行中。

      这是一个工作代码sn-p(点击下面的“运行代码sn-p”并展开到整页):

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
      
      <div class="container-fluid mt-4">
          <div class="row justify-content-center">
              <div class="col-auto mb-3">
                  <div class="card" style="width: 18rem;">
                      <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="card-link">Card link</a>
                          <a href="#" class="card-link">Another link</a>
                      </div>
                  </div>
              </div>
              <div class="col-auto mb-3">
                  <div class="card" style="width: 18rem;">
                      <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="card-link">Card link</a>
                          <a href="#" class="card-link">Another link</a>
                      </div>
                  </div>
              </div>
              <div class="col-auto mb-3">
                  <div class="card" style="width: 18rem;">
                      <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="card-link">Card link</a>
                          <a href="#" class="card-link">Another link</a>
                      </div>
                  </div>
              </div>
              <div class="col-auto mb-3">
                  <div class="card" style="width: 18rem;">
                      <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="card-link">Card link</a>
                          <a href="#" class="card-link">Another link</a>
                      </div>
                  </div>
              </div>
              <div class="col-auto mb-3">
                  <div class="card" style="width: 18rem;">
                      <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="card-link">Card link</a>
                          <a href="#" class="card-link">Another link</a>
                      </div>
                  </div>
              </div>
              <div class="col-auto mb-3">
                  <div class="card" style="width: 18rem;">
                      <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="card-link">Card link</a>
                          <a href="#" class="card-link">Another link</a>
                      </div>
                  </div>
              </div>
              <div class="col-auto mb-3">
                  <div class="card" style="width: 18rem;">
                      <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="card-link">Card link</a>
                          <a href="#" class="card-link">Another link</a>
                      </div>
                  </div>
              </div>
          </div>
      </div>

      【讨论】:

      • 这样做的问题是卡片会有不同的高度。
      • @ethmz 这可以通过将类 h-100 添加到卡中来解决。很好的答案,正是我想要的!
      猜你喜欢
      • 2016-07-01
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 2020-07-20
      • 2019-02-23
      • 1970-01-01
      相关资源
      最近更新 更多