如何使两张卡居中(Bootstrap)?
Posted
技术标签:
【中文标题】如何使两张卡居中(Bootstrap)?【英文标题】:How to center the two cards (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" 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" 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
【问题讨论】:
【参考方案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;
【讨论】:
以上是关于如何使两张卡居中(Bootstrap)?的主要内容,如果未能解决你的问题,请参考以下文章
Bootstrap 网格系统 - 如何使两列高度相等? [复制]