How to automatically stretch the height of specific item in CSS Grid?
I have simple masonry layout done by 2 x 3 CSS Grid. Everything works fine except the red area, which I would like to stretch vertically in order to place the containing text element just below the element in green area.
When I set auto height of grid rows, the red area is only that high as its inner element, while I would like to have this behavior happening in green area.
What is happening now:
Expected behavior:
I could probably achieve this by setting padding-bottom or height to the element in red area, but the elements in the right column have dymanic height, so this is probably not the way... Also I could obviously group the content from green and red areas together, but this would be problematic too in my case...
So is it possible to make this happen just with the following markup and CSS Grid features, please?
EDIT: In CSS-only masonry layout is being said, with item dimensions undefined, this is not possible to do without JS. But there is one element which has static height (the inner element of green area). Does it make any change?
.wrapper {
display: grid;
grid: repeat(3, auto) / 1fr 1fr;
}
.wrapper > div > * {
margin: 5px;
padding: 5px;
border: 1px solid black;
}
.item-1 {
grid-area: 1 / 2 / 2 / 3;
background: yellow;
}
.item-2 {
grid-area: 1 / 1 / 3 / 2;
background: green;
}
.item-3 {
grid-area: 3 / 1 / 4 / 2;
background: red;
}
.item-4 {
grid-area: 2 / 2 / 4 / 3;
background: darkturquoise;
}
.item-2 div {
height: 100px;
}
<div class="wrapper">
<div class="item-1">
<p>Lorem ipsum Lorem ipsum Lorem ipsum</p>
</div>
<div class="item-2">
<div></div>
</div>
<div class="item-3">
<p>Lorem ipsum Lorem ipsum Lorem ipsum</p>
</div>
<div class="item-4">
<p>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</p>
</div>
</div>