Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active January 18, 2021 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodie/dc78c744578afefb5b9909e9605a6122 to your computer and use it in GitHub Desktop.
Save kodie/dc78c744578afefb5b9909e9605a6122 to your computer and use it in GitHub Desktop.
SCSS grid @mixin
@mixin grid($cols: 4, $gap: 2rem, $item: '> *') {
&:after {
clear: left;
content: '';
display: block;
}
#{$item} {
box-sizing: border-box;
float: left;
width: calc(calc(100% / #{$cols}) - calc(calc(#{$gap} * #{$cols - 1}) / #{$cols}));
&:not(:nth-child(#{$cols}n)) {
margin-right: $gap;
}
&:nth-child(n+#{$cols + 1}) {
margin-top: $gap;
}
}
}
.two-col {
@include media('<tablet') {
@include grid(1);
}
@include media('>=tablet') {
@include grid(2);
}
}
.three-col {
@include media('<tablet') {
@include grid(1);
}
@include media('>=tablet', '<desktop') {
@include grid(2);
}
@include media('>=desktop') {
@include grid(3);
}
}
.four-col {
@include media('<tablet') {
@include grid(1);
}
@include media('>=tablet', '<desktop') {
@include grid(2);
}
@include media('>=desktop') {
@include grid(4);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment