我正在尝试跨容器垂直对齐可变高度元素,即每个容器中的第一个元素相互垂直对齐,每个容器中的第二个元素相互垂直对齐,等等。
我正在使用 flexbox 但不确定这是否可能?或者是否可以使用 CSS Grid?
期望的结果
查看演示,我还没有设法让它工作。
main {
display: flex;
flex-wrap: wrap;
}
.container {
background: grey;
margin: 0 10px 20px;
padding: 10px;
width: 200px;
}
.top {
background: red;
}
.middle {
background: blue;
}
.bottom {
background: green;
}
<main>
<div class="container">
<div class="top">Some text here, Some text here, Some text here</div>
<div class="middle">And some here, And some here, And some here, And some here, And some here, And some here</div>
<div class="bottom">And a little here too</div>
</div>
<div class="container">
<div class="top">Some text here, Some text here</div>
<div class="middle">And some here, And some here, And some here, And some here, And some here, And some here, And some here, And some here, And some here</div>
<div class="bottom">And a little here too, And a little here too</div>
</div>
<div class="container">
<div class="top">Some text here, Some text here, Some text here, Some text here, Some text here</div>
<div class="middle">And some here</div>
<div class="bottom">And a little here too</div>
</div>
<div class="container">
<div class="top">Some text here, Some text here, Some text here</div>
<div class="middle">And some here, And some here, And some here, And some here, And some here, And some here</div>
<div class="bottom">And a little here too</div>
</div>
<div class="container">
<div class="top">Some text here, Some text here, Some text here</div>
<div class="middle">And some here, And some here, And some here, And some here, And some here, And some here</div>
<div class="bottom">And a little here too</div>
</div>
<div class="container">
<div class="top">Some text here, Some text here, Some text here</div>
<div class="middle">And some here, And some here, And some here, And some here, And some here, And some here</div>
<div class="bottom">And a little here too</div>
</div>
<div class="container">
<div class="top">Some text here, Some text here, Some text here</div>
<div class="middle">And some here, And some here, And some here, And some here, And some here, And some here</div>
<div class="bottom">And a little here too</div>
</div>
</main>