Last active
April 22, 2021 23:55
-
-
Save karlazz/0f6ff048eb350857fed6b5e01673fd67 to your computer and use it in GitHub Desktop.
Automated reponsive grid from Heydon Pickering and further grid notes
This file contains hidden or 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
.container { | |
display: grid; | |
grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); | |
grid-gap: 1rem; | |
} |
/* and here is a solution for leftover grid items from https://css-irl.info/controlling-leftover-grid-items/ */
.grid {
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-gap: 20px;
}
li {
grid-column: span 2;
}
/* Dealing with 2 orphan items */
li:last-child:nth-child(3n - 1) {
grid-column-end: -2;
}
li:nth-last-child(2):nth-child(3n + 1) {
grid-column-end: 4;
}
/* Dealing with single orphan */
li:last-child:nth-child(3n - 2) {
grid-column-end: 5;
}
Most of my reading started here:
https://webdesign.tutsplus.com/articles/flexbox-vs-css-grid-which-should-you-use--cms-30184
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And an improvement to avoid overflow in narrow narrow columns:
grid-template-columns: repeat(auto-fill, minmax(min(10rem, 100%), 1fr));