I have a container, which contains blocks inside. The number of the blocks and their height can be different, but the width is 45% for all, so that two blocks can fit into one row. I currently use flexbox
with flex-wrap: wrap
, but there is an issue, which you can see on the screenshot below. The wanted result is the one on the right. How can that be achieved?
HTML:
.container {
display: flex;
flex-wrap: wrap;
}
.block {
width: 45%;
border: 1px solid black;
background-color: grey;
}
<div class="container">
<div class="block" style="height: 500px;"></div>
<div class="block" style="height: 200px;"></div>
<div class="block" style="height: 100px;"></div>
<div class="block" style="height: 300px;"></div>
<div class="block" style="height: 500px;"></div>
</div>