首页 > 解决方案 > Bootstrap - 如何在卡之间添加空间

问题描述

我试图在我的卡片之间放置空间。

我有 4 张卡并排。但是当我mr-3在卡片 div 上使用时,最后一张卡片在下面。我不希望这种情况发生。

如何将所有 4 张卡片与它们之间的空格保持在同一行/行中?

我也试过d-flex justify-content-around,但它不起作用。

下面是我的代码

<div class="container">
      <div class="row">
        <div class="card col-md-3">
          <img src="..." class="card-img-top" alt="...">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <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="btn btn-primary">Go somewhere</a>
          </div>
        </div>
        <div class="card col-md-3">
          <img src="..." class="card-img-top" alt="...">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <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="btn btn-primary">Go somewhere</a>
          </div>
        </div>
        <div class="card col-md-3">
          <img src="..." class="card-img-top" alt="...">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <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="btn btn-primary">Go somewhere</a>
          </div>
        </div>
        <div class="card col-md-3">
          <img src="..." class="card-img-top" alt="...">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <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="btn btn-primary">Go somewhere</a>
          </div>
        </div>
      </div>
    </div>

第一张图片: 在此处输入图像描述

最后一张卡片在下面的第二张图片: 在此处输入图像描述

标签: htmlbootstrap-4

解决方案


把卡放在一个col...然后试试

卡片,卡片组,卡片列没有响应功能


推荐阅读