Created
February 20, 2024 19:04
-
-
Save AoiYamada/682e821ce0415d0da8b282db9f2e7298 to your computer and use it in GitHub Desktop.
CodePen Home Pure CSS waterfall grid layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
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