我有一个具有动态高度的垂直堆叠框列表。我希望每个框的高度都与其中最高的一样高。如何使用显示网格来实现这一点?
这是我所拥有的 - 我希望框 1 始终与框 2 一样高 - 反之亦然:
.container {
display: grid;
grid-template-columns: repeat(1, 1fr);
row-gap: 1rem;
}
.box {
border: 1px solid #ddd;
padding: 1rem;
margin-bottom: 1rem;
}
<div class="container">
<div class="box">
<strong>Box 1:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis lectus quis sem lacinia nonummy. Proin mollis lorem non dolor. In hac habitasse platea dictumst. Nulla ultrices odio. Donec augue. Phasellus dui.
</div>
<div class="box">
<strong>Box 2:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis lectus quis sem lacinia nonummy. Proin mollis lorem non dolor. In hac habitasse platea dictumst. Nulla ultrices odio. Donec augue. Phasellus dui.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis lectus quis sem lacinia nonummy. Proin mollis lorem non dolor. In hac habitasse platea dictumst. Nulla ultrices odio. Donec augue. Phasellus dui.
</div>
</div>
添加
grid-auto-rows: 1fr