【发布时间】:2019-11-20 22:36:25
【问题描述】:
所以我正在编写一个代码,我需要在使用 flex 时将卡片均匀地排成一行。但是,我在右侧有一些间距,无法找出发生这种情况的原因。我尝试检查元素,但它只是显示整个卡片向右延伸,但它这样做的背后没有真正的原因。我滚动浏览了 CSS 代码,右侧没有额外的宽度。
<section id="jobs">
<!--Employing cards-->
<div class="container-fluid container-fluid-shorter bg-white">
<!--Assistant card-->
<div class="row">
<div class="col-md-6 col-lg-4 my-3">
<div class="card width-37">
<div class="card-body d-flex align-items-center justify-content-between">
<h6 class="card-title font-weight-lighter pb-3">Custom units</h6>
<p class="card-text">
<h4 class="text-grey font-weight-light text-capitalize pb-3 pt-3">home page hero</h4>
</div>
</div>
</div>
<div class="col-md-6 col-lg-4 my-3">
<div class="card width-37">
<div class="card-body d-flex align-items-center justify-content-between">
<h5 class="card-title font-weight-lighter pb-3">Vlastní jednotky</h5>
<p class="card-text">
<h4 class="text-grey font-weight-light text-capitalize pb-3 pt-3">home page hero</h4>
</div>
</div>
</div>
<div class="col-md-6 col-lg-4 my-3">
<div class="card width-37">
<div class="card-body d-flex align-items-center justify-content-between">
<h5 class="card-title font-weight-lighter pb-3">Vlastní jednotky</h5>
<p class="card-text">
<h4 class="text-grey font-weight-light text-capitalize pb-3 pt-3">home page hero</h4>
</div>
</div>
</div>
</div>
</div>
<!--End of employing cards section-->
</section>
我对 CSS 所做的调整:
.width-37{
max-width: 37.5vh;
}
.card-body{
padding-left: 0; !important;
padding-right: 0; !important;
}
我试图将所有项目放置在每个项目之间有小间距的行中,并且当您为不同的屏幕尺寸设置大、中、小行时,所有项目都会创建行。出于某种原因,弹性项目在每个项目的右侧做间距。它是 480 像素宽和 180 像素高。我希望它是 180 x 180 像素,所以高度和宽度相同。有人知道为什么会这样吗?
【问题讨论】:
-
请提供MCVE。
-
你为什么使用 37.5vh?
-
当然会做饥饿之星!
-
Zim 的完美宽度。
-
您将卡片的宽度设置为视口高度的 37.5%。我不确定你想这样做。如果高度非常小,一切都会开始溢出。列类提供的宽度有什么问题?卡片是否太宽?
标签: html css bootstrap-4