You have fixed heights on your child elements (.block
). Based on that information, we can extrapolate the height of the container (#wrapper
).
By knowing the height of the container, your layout can be achieved using CSS Flexbox with flex-direction: column
and flex-wrap: wrap
.
A fixed height on the container serves as a breakpoint, telling flex items where to wrap.
#wrapper {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 120px;
width: 516px;
}
.block {
width: 90px;
flex: 0 0 50px;
margin: 5px;
background-color: red;
}
.bigger {
flex-basis: 110px;
}
<div id="wrapper">
<div class="block"></div>
<div class="block"></div>
<div class="block bigger"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…