我正在尝试开发一个具有以下要求的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>
答案 0 :(得分:7)
经过一些实验,这个很容易解决:我需要将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>
希望这可以帮助那些陷入困境的人。