我正在尝试开发一个具有以下要求的Bootstrap 4卡网格:
class="row"
内,因为我不知道总数会有多少卡,我希望行在不同的屏幕断点处看起来很好。col-sm-6 col-lg-4
)。我已经设法得到了几乎所有的方式,但我遇到了一个问题:在我的卡上设置class="h-100"
以确保它们都是相同的高度杀死每张卡底部的边距。
有没有办法确保任何给定显示行中的所有卡都是相同的高度,同时保留其底部的边距?
HTML代码:
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6">
<div class="card h-100 mb-4" style="background-color:#ff0000;">
Test card content.
</div>
</div>
<div class="col-md-4 col-sm-6">
<div class="card h-100 mb-4" style="background-color:#00ff00;">
Test card content. Test card content. Test card content. Test card content.
</div>
</div>
<div class="col-md-4 col-sm-6">
<div class="card h-100 mb-4" style="background-color:#0000ff;">
Test card content. Test card content. Test card content. Test card content. Test card content. Test card content. Test card content. Test card content.
</div>
</div>
<div class="col-md-4 col-sm-6">
<div class="card h-100 mb-4" style="background-color:#0f0f0f;">
Test card content.
</div>
</div>
</div>
</div>
经过一些实验,这个很容易解决:我需要将mb-4类添加到包含列,而不是卡本身:
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6 mb-4">
<div class="card h-100" style="background-color:#ff0000;">
Test card content.
</div>
</div>
<div class="col-md-4 col-sm-6 mb-4">
<div class="card h-100" style="background-color:#00ff00;">
Test card content. Test card content. Test card content. Test card content.
</div>
</div>
<div class="col-md-4 col-sm-6 mb-4">
<div class="card h-100" style="background-color:#0000ff;">
Test card content. Test card content. Test card content. Test card content. Test card content. Test card content. Test card content. Test card content.
</div>
</div>
<div class="col-md-4 col-sm-6 mb-4">
<div class="card h-100" style="background-color:#0f0f0f;">
Test card content.
</div>
</div>
</div>
</div>
希望这可以帮助那些陷入困境的人。