如何在引导卡之间增加垂直间距

时间:2019-05-17 12:25:15

标签: html bootstrap-4

我正在使用Boostrap卡,以下是它们目前的外观: enter image description here

现在我要做的是在卡之间添加垂直空间,以使卡1和卡3以及卡2和卡4不会粘在一起。

以下是我目前所拥有卡的代码和设置:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="col-sm-6">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 1</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>
    <div class="col-sm-6">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 2</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>
    <div class="col-sm-6">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 3</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>
    <div class="col-sm-6">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 4</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>
  </div>
</div>

3 个答案:

答案 0 :(得分:2)

mb-3添加类<div class="col-sm-6 mb-3">

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="col-sm-6 mb-3">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 1</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>
    <div class="col-sm-6 mb-3">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 2</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>

    <div class="col-sm-6 mb-3">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 3</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>
    <div class="col-sm-6 mb-3">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">CARD 4</h5>
          <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>

  </div>
</div>

如果您需要更多空间,可以使用mb-4 mb-5

这样的引导程序类

更多信息 here

答案 1 :(得分:0)

margin-bottom: 20px文件的card类内添加css。检查以下简单的CSS。

在style.css文件中

.card { 
    margin-bottom: 20px !important;
 }

答案 2 :(得分:0)

我会添加这样的内容 (SCSS):

div[class^="col-"] {
   padding-top: 1rem;
   padding-bottom: 1rem;

   > h1,
   > h2,
   > h3,
   > h4,
   > h5,
   > h6 {
      margin-top: 0;
   }
}

* + * {
   :last-child {
       margin-bottom: 0;
   }
}

...一般处理垂直空间。