My target is to use CSS grid layout for a two-column masonry layout of boxes. Given an element with children:
<section>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
bring the children to sort themselves alternately into columns. My idea was to have two grid areas left
and right
and telling the children to split into them:
section {
display: grid;
grid-template-areas: "left right";
}
div:nth-child(odd) {
grid-area: left;
}
div:nth-child(even) {
grid-area: right;
}
Here's a JSBin that illustrates my current state: https://jsbin.com/zaduruv/edit?html,css,output
Unfortunately, the elements react quite identical to as if they had position:absolute
set. That is, they all crowd towards the top and overlap one another.
Is there any possibility with the CSS grid layout properties to bring the children to line up in the columns, like they'd do normally with position: static
?