我想使用 Bootstrap 4 fixed-width cards 制作响应式 卡片 组。我在这里发布了下面的代码,但它没有响应。为什么?
<div class="card-deck">
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
<div class="card-body">
<h4 class="card-title">Title 1</h4>
<p>Small text here</p>
<small class="text-muted">3 mins ago</small>
</div>
</div>
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
<div class="card-body">
<h4 class="card-title">Title 2</h4>
<p>Small text here</p>
<small class="text-muted">3 mins ago</small>
</div>
</div>
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
<div class="card-body">
<h4 class="card-title">Title 3</h4>
<p>Small text here</p>
<small class="text-muted">3 mins ago</small>
</div>
</div>
<div class="card col-lg-2 col-md-3 col-sm-4 col-6" style="max-width: 12rem;">
<div class="card-body">
<h4 class="card-title">Title 4</h4>
<p>Small text here</p>
<small class="text-muted">3 mins ago</small>
</div>
</div>
原文由 Devon Ravihansa 发布,翻译遵循 CC BY-SA 4.0 许可协议
对于带有 固定宽度 卡片的 Bootstrap 4 卡片组,请执行以下操作:
将每张卡片放入带有类
col-auto mb-3
的列中(自动宽度列 + margin-bottom 三个单位)。要将它们居中,请将
justify-content-center
类添加到该行。这是一个有效的代码片段(点击下面的“运行代码片段”并展开到整页):