My markup looks like so:
<div class="row">
<div class="cell1">Cell 1</div>
<div class="cell2">Cell 2<br />Context: cell 2</div>
<div class="cell3">Cell 3<br />Context: cell 3</div>
<div class="cell4">Cell 4</div>
</div>
I need to achieve a 2 column grid layout where I can put any of the divs in either column and there will be no vertical gaps. I cannot alter the markup. Example scenarios are visualised below.
I tried using a grid-template
and allowing the child divs to use grid-area
in any combination to achieve the multiple desired scenarios. For example:
.row {
display: grid;
grid-template: "col1 col2" / 1fr 1fr;
}
.cell1,
.cell3 {
grid-area: col1;
}
.cell2,
.cell4 {
grid-area: col2;
}
This allocates divs to columns correctly, but they layer on top of each other inside the areas rather than stack vertically:
Is the desired layout possible?