I'm using grid-template to set up a simple grid structure for one row and four columns. The two leftmost columns have a fixed width, and the remaining two should fill the remaining space.
However, the second column is optional - it may not be present at all. In this case I do not want to reserve any space for it. The two rightmost columns should fill the space.
This is obviously not possible with grid-template. Is it possible at all?
.grid {
display: grid;
grid-template-areas: "one two three four";
grid-template-columns: 8rem 8rem 1fr 1fr;
}
.one { background: #404788aa; grid-area: one; }
.two { background: #287d8eaa; grid-area: two; }
.three { background: #3cbb75aa; grid-area: three; }
.four { background: #dce319aa; grid-area: four; }
<div class="grid">
<div class="one">One</div>
<div class="two">Two</div>
<div class="three">Three</div>
<div class="four">Four</div>
</div>
<hr><p>Three and Four should fill the space:</p>
<div class="grid">
<div class="one">One</div>
<div class="three">Three</div>
<div class="four">Four</div>
</div>