对齐不同身高的孩子

时间:2018-07-31 20:04:02

标签: css flexbox

是否可以通过包装子代并将其与顶部对齐来创建Flexbox布局?

.container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.container .element {
  flex: 0 0 auto;
}

创建此:

current example

但我的计划是实现这一目标:

wanted example

1 个答案:

答案 0 :(得分:0)

.container {
  border: 1px solid black;
  padding: 10px;
  height: 250px;
  
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  align-content: flex-start;
  
  overflow: hidden;
  resize: both;
}

.container div {
  border: 5px solid #AAA;
  background-color: #DDD;
  margin: 3px;
  height: 100px;
  width: 50px;
}

.container div:nth-child(3n) {
  height: 40px;
}
<div>
  <div class="container">
    <div></div><div></div><div></div>
    <div></div><div></div><div></div>
    <div></div><div></div><div></div>
  </div>
</div>
Some Text