Last active
January 18, 2021 22:22
-
-
Save kodie/dc78c744578afefb5b9909e9605a6122 to your computer and use it in GitHub Desktop.
SCSS grid @mixin
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
@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