我用下面的html用bootstrap 4构建了一个网格。
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="row">
<div class="col-sm-12 col-md-3">
<div class="row">
<div class="col-lg-12">
here are different heights possible
</div>
</div>
<div class="row align-items-end">
<div class="col-lg-12 date">
should always be at bottom (like the fourth date)
</div>
</div>
</div>
<div class="col-sm-12 col-md-3">
<div class="row">
<div class="col-lg-12">
here are different heights possible
</div>
</div>
<div class="row align-items-end">
<div class="col-lg-12 date">
should always be at bottom (like the fourth date)
</div>
</div>
</div>
<div class="col-sm-12 col-md-3">
<div class="row">
<div class="col-lg-12">
here are different heights possible
here are different heights possible
here are different heights possible
</div>
</div>
<div class="row align-items-end">
<div class="col-lg-12 date">
should always be at bottom (like the fourth date)
</div>
</div>
</div>
</div>
我希望日期总是在第二行的底部。也许图片更好地解释了这个问题。前三个日期与弹性框底部的第四个日期不在同一行中:
发布于 2019-03-04 22:56:36
无法在不同的flexbox父组件的子组件中平等地对齐内容。但是,您可以使用d-flex
,然后使用mt-auto
(margin-top:auto
)将日期推到列的底部,从而使列也成为flexbox容器。
<div class="col-sm-12 col-md-3 d-flex flex-column">
<div class="row">
<div class="col-lg-12">
here are different heights possible
</div>
</div>
<div class="row mt-auto">
<div class="col-lg-12 date">
date
</div>
</div>
</div>
演示:https://www.codeply.com/go/gLYW7liCfc
另请参阅:bootstrap 4 cards - vertical alignment body with variable header line rows
https://stackoverflow.com/questions/54985467
复制相似问题