I have a complex 2-column grid layout, and the example shown here is just one part of it. The complete code follows a similar structure. I am looking for a way to ensure that the green box always stays close to the red box in the layout, without having a fixed size. If the content in the right column exceeds that of the left first item, I want block D and block B to be positioned next to each other seamlessly.
.container {
display: grid;
grid-template-areas: "d c" "b a";
grid-column-gap: 16px;
grid-template-columns: 1fr 1fr;
align-items: baseline;
}
.a {
grid-area: a;
background-color: blue;
}
.b {
grid-area: b;
background-color: green;
}
.c {
grid-area: c;
background-color: purple;
}
.d {
grid-area: d;
background-color: red;
}
.block {
/* height:300px; */
}
<div class="container">
<div class="block a">
Lorem ipsum dolor sit amet.
</div>
<div class="block b">
Lorem ipsum dolor sit amet, consectetur adipisicing.
</div>
<div class="block c">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi quod ea aperiam consequatur fugiat libero voluptate accusantium amet corporis laborum in, quae ratione, atque assumenda. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid
enim labore, eaque quidem repellendus atque!
</div>
<div class="block d">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestiae blanditiis laudantium sit, pariatur omnis quibusdam?
</div>
</div>