【问题标题】:How to center the two cards (Bootstrap)?如何使两张卡居中(Bootstrap)?
【发布时间】:2021-06-11 16:31:51
【问题描述】:

[网站][1] [1]:https://i.stack.imgur.com/CmQRP.png

你好,我想把我的两张卡片放在中间,但我不知道怎么做。

  <div>
    <div class="card" style="width: 18rem;">
      <img class="card-img-top" src="img/v.jpg" alt="Card image cap" style="width: 286px; height: 180px;">
      <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>
<div>
  <div >
    <div class="card" style="width: 18rem;">
      <img class="card-img-top" src="img/v.jpg" alt="Card image cap" style="width: 286px; height: 180px;">
      <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>```


  [1]: https://i.stack.imgur.com/CmQRP.png

【问题讨论】:

    标签: html css bootstrap-4 twitter-bootstrap-3


    【解决方案1】:

    将你所有的卡片包装在一个容器中并添加以下代码:

    .container {
      display: flex;
      width: 80vw; //Change the value if your want
      margin: auto;
    /*   flex-direction: column; */ //Uncomment if you want the card to be in a line
    }
    

    在每张卡片中:

    .card {
      flex: 1;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-30
      • 2018-08-30
      • 2021-04-16
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 2022-11-01
      • 2018-11-24
      • 2017-07-02
      相关资源
      最近更新 更多