[英]How to minimize Card spacing in Bootstraps 4
I just created 4 card using bootstraps 4.5 version but the spacing is really bad and I do not know how to reduce the spacing of card you can the image if you still confuse我刚刚使用 bootstraps 4.5 版本创建了 4 张卡片,但间距真的很糟糕,我不知道如何减少卡片的间距,如果您仍然感到困惑,您可以使用图像
.card { width : 55%; min-height: 100; margin: 2%; } .card-img-top { height: 150px; object-fit: cover; } .card-body{ box-shadow: 0 0 20px 7px rgba(0,0,0,0.1); }
<div class="container"> <div class="row"> <div class="col-md-4"> <div class="card text-md-center"> <img src="Nike.jpg" class="card-img-top"> <div class="card-body"> <h5 class="card-title">Shoes</h5> <p class="card-text">Some quick example text</p> <a href="#">Buy</a> </div> </div> </div> <div class="col-md-4"> <div class="card text-md-center"> <img src="chevrolet.jpg" class="card-img-top"> <div class="card-body"> <h5 class="card-title">Car</h5> <p class="card-text">Some quick example text</p> <a href="#">Buy</a> </div> </div> </div> <div class="col-md-4"> <div class="card text-md-center"> <img src="asuslap.jpg" class="card-img-top"> <div class="card-body"> <h5 class="card-title">Laptop</h5> <p class="card-text">Some quick example text</p> <a href="#">Buy</a> </div> </div> </div> <div class="col-md-4"> <div class="card text-md-center"> <img src="asusphone.jpg" class="card-img-top"> <div class="card-body"> <h5 class="card-title">Phone</h5> <p class="card-text">Some quick example text</p> <a href="#">Buy</a> </div> </div> </div> </div>
I have searched it in google but I still not find it (How to reduce spacing of Card), maybe you can help me我在谷歌搜索过,但还是没有找到(如何减少卡片的间距),也许你可以帮助我
I added a flex-display
to your .row
class and justified everything in the center.我在你的
.row
类中添加了一个flex-display
并证明了中心的所有内容。 Spacing looks fine to me.间距对我来说很好。
.card { width: 55%; min-height: 100; margin: 2%; } .card-img-top { height: 150px; object-fit: cover; } .card-body{ box-shadow: 0 0 20px 7px rgba(0,0,0,0.1); } .row { display: flex; justify-content: center; }
<div class="container"> <div class="row"> <div class="col-md-4"> <div class="card text-md-center"> <img src="Nike.jpg" class="card-img-top"> <div class="card-body"> <h5 class="card-title">Shoes</h5> <p class="card-text">Some quick example text</p> <a href="#">Buy</a> </div> </div> </div> <div class="col-md-4"> <div class="card text-md-center"> <img src="chevrolet.jpg" class="card-img-top"> <div class="card-body"> <h5 class="card-title">Car</h5> <p class="card-text">Some quick example text</p> <a href="#">Buy</a> </div> </div> </div> <div class="col-md-4"> <div class="card text-md-center"> <img src="asuslap.jpg" class="card-img-top"> <div class="card-body"> <h5 class="card-title">Laptop</h5> <p class="card-text">Some quick example text</p> <a href="#">Buy</a> </div> </div> </div>
If you don't problem about the width card, you can remove width : 55%;
如果你对宽度卡没有问题,你可以去掉
width : 55%;
in your CSS.在你的 CSS 中。 It would be better.
会更好。
OR或者
You can change the value in every col-md
class.您可以更改每个
col-md
类中的值。 The spacing the of every card is caused by that.每张卡的间距都是由此造成的。
The Bootstrap way to do so is to dynamically adjust the column width depending on the width of the browser/screen. Bootstrap 这样做的方法是根据浏览器/屏幕的宽度动态调整列宽。 Do not set the width manually.
不要手动设置宽度。 Let the media query breakpoints do the job.
让媒体查询断点完成这项工作。
HTML HTML
<div class="container">
<div class="row">
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Shoes</h5>
<p class="card-text">Some quick example text</p>
<a href="#">Buy</a>
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Car</h5>
<p class="card-text">Some quick example text</p>
<a href="#">Buy</a>
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Laptop</h5>
<p class="card-text">Some quick example text</p>
<a href="#">Buy</a>
</div>
</div>
</div>
<div class="col-6 col-md-4 col-lg-3">
<div class="card text-md-center">
<img src="http://placehold.jp/320x180.png" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Phone</h5>
<p class="card-text">Some quick example text</p>
<a href="#">Buy</a>
</div>
</div>
</div>
</div>
CSS CSS
.card {
/* width: 55%; */
min-height: 100;
margin: 2%;
}
.card-img-top {
height: 150px;
object-fit: cover;
}
.card-body {
box-shadow: 0 0 20px 7px rgba(0, 0, 0, 0.1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.