Skip to content

Instantly share code, notes, and snippets.

@AoiYamada
Created February 20, 2024 19:04
Show Gist options
  • Save AoiYamada/682e821ce0415d0da8b282db9f2e7298 to your computer and use it in GitHub Desktop.
Save AoiYamada/682e821ce0415d0da8b282db9f2e7298 to your computer and use it in GitHub Desktop.
CodePen Home Pure CSS waterfall grid layout
// credit to: https://codepen.io/michellebarker/pen/RwMWYpb
<div class="grid">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
* {
box-sizing: border-box;
}
.grid {
columns: 18rem;
gap: 1rem;
counter-reset: grid;
}
.item + .item {
margin-top: 1rem;
}
.item {
break-inside: avoid;
aspect-ratio: 4 / 3;
background: pink;
padding: 1rem;
border-radius: 0.75rem;
}
.item::before {
counter-increment: grid;
content: counter(grid);
}
.item:nth-child(3n) {
aspect-ratio: 1;
background: lavender;
}
.item:nth-child(3n - 1) {
aspect-ratio: 2 / 3;
background: lightblue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment