<div class="container container--1">
<div class="item">1</div>
<div class="item">2 2 2 2 2 2 2 2 2 2 2 2</div>
<div class="item">3</div>
</div>
<br>
<div class="container container--2">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<br>
<div class="container container--3">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<br>
<div class="container container--4">
<div class="item">1</div>
<div class="item">2 2 2</div>
<div class="item">3</div>
</div>
<br>
<div class="container container--5">
<div class="item">1</div>
<div class="item">2 2 2 2 2 2 2 2 2 2 2 2</div>
<div class="item">3</div>
</div>
/* -------- Skip this base code -------- */
* { box-sizing: border-box; } .container { display: grid; grid: '. . .'; gap: 1px; padding: 1px; border: 16px solid silver; color: white; } .item { padding: 8px; background: coral; } .item:nth-child(2) { background: royalblue; }
.container--1 { grid-auto-columns: auto; }
.container--2 { grid-auto-columns: 40px 50%; }
.container--3 { grid-auto-columns: 1fr 4fr; }
.container--4 { grid-auto-columns: min-content; }
.container--5 { grid-auto-columns: max-content; }
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.