<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
</div>
<div class="grid-container masonry-auto-flow">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
body {
width: 100vw;
min-height: 100vh;
counter-reset: section;
font-family: "Exo", Arial, sans-serif;
font-size: 20px;
font-weight: 600;
padding: 10px;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
}
.grid-container {
display: inline-grid;
grid: masonry / repeat(3, 1fr);
border: 1px solid;
gap: 10px;
margin: 5px;
}
.grid-container.masonry-auto-flow {
masonry-auto-flow: next;
}
.grid-item {
min-width: 15vw;
background-color: #f90;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-size: 2rem;
}
.grid-container div:nth-child(1) {
background-color: #f36;
height: 8em;
}
.grid-container div:nth-child(2) {
background-color: #360;
height: 14em;
}
.grid-container div:nth-child(3) {
background-color: #09f;
height: 10em;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.