Keeping your HTML as-is, the layout is not natively possible with flexbox. This is primarily because of the 2 x 2 box occupying the third and fourth columns. The closest you can get is this:
#wrapper{
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: flex-start;
height: 180px;
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"></div>
<div class="block bigger"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block bigger"></div>
<div class="block"></div>
<div class="block bigger"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
As you can see, the big box is broken up between columns.
As mentioned in the other post you referenced, since you have fixed heights on your child elements (.block
), we can determine the height of the container (.wrapper
).
By knowing the height of the container, the layout above can be achieved using flex-direction: column
and flex-wrap: wrap
.
A fixed height on the container serves as a breakpoint, telling flex items where to wrap.
Alternatively, if you can add containers, then the layout is easy. Just create four nested flex containers to hold columns 1, 2, 3-4 and 5, and you're done.
#wrapper {
display: flex;
width: 516px;
}
section {
display: flex;
flex-direction: column;
}
.block {
width: 90px;
height: 50px;
margin: 5px;
background-color: red;
}
.bigger {
flex-basis: 110px;
}
section:nth-child(3) {
flex-direction: row;
flex-wrap: wrap;
flex: 0 0 200px;
}
section:nth-child(3)>.block:last-child {
flex: 0 0 190px;
height: 110px;
}
<div id="wrapper">
<section>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</section>
<section>
<div class="block bigger"></div>
<div class="block"></div>
</section>
<section>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</section>
<section>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</section>
</div>
Otherwise, see this post for more details and other options: