<section class="grid grid1">
<div class="item">item1</div>
<div class="item">item2</div>
<div class="item">item3</div>
<div class="item">item4</div>
</section>
<section class="grid grid2">
<div class="item">item1</div>
<div class="item">item2</div>
<div class="item">item3</div>
<div class="item">item4</div>
</section>
.grid {
display: grid;
grid-gap: 20px;
}
.grid1 {
grid-template-columns: repeat(4, 100px);
}
.grid2 {
display: none;
}
/*
.grid2 {
grid-template-columns: repeat(auto-fit, 100px);
}
*/
This Pen doesn't use any external JavaScript resources.