I have a simple grid layout with a grid-gap and defined grid-areas. However not all areas have content all the time. If an area doesn't have content, I don't want there to be a double the gap in between the items. Is there a way to ignore the gap on empty areas, without using a different grid-template, to ignore the double gap between items?
Example:
.grid {
display: grid;
grid-template-areas: "area-1" "empty-area" "area-3" "area-4";
grid-template-columns: auto;
grid-gap: 20px;
}
.area-1 {
grid-area: area-1;
background: red;
}
.area-3 {
grid-area: area-3;
background: green;
}
.area-4 {
grid-area: area-4;
background: blue;
}
<div class="grid">
<div class="area-1">Hello</div>
<!-- empty area is missing -->
<div class="area-3">World</div>
<div class="area-4">!</div>
</div>
grid-gap
. If your goal is to have a flexible layout, CSS offers flexbox (as the name describes). A "flexible" grid could work but was not made for that purpose and your project will be always open to layout errors – Broke