-
-
Save jensgro/687cef1ab0a741da1075a9f8e4d060de to your computer and use it in GitHub Desktop.
A simple SASS utility to create layouts based on CSS Grid
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
// These are the mixins | |
@mixin grid-layout($column-count, $column-gap: 3rem, $row-gap: null) { | |
$row-gap: if($row-gap == null, $column-gap, $row-gap); | |
display: grid; | |
grid-template-columns: repeat($column-count, 1fr); | |
grid-gap: $row-gap $column-gap; | |
gap: $row-gap $column-gap; | |
} | |
@mixin grid-column-start($number) { | |
grid-column-start: $number; | |
} | |
@mixin grid-row-start($number) { | |
grid-row-start: $number; | |
} | |
@mixin grid-column-span($count) { | |
grid-column-end: span $count; | |
} | |
@mixin grid-row-span($count) { | |
grid-row-end: span $count; | |
} |
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
// And this is how to use them | |
.grid-container { | |
@include grid-layout(12, 2rem); // The $row-gap will automatically be the same as $column-gap if you omit it | |
} | |
.grid-item { | |
@include grid-column-start(2); | |
@include grid-column-span(4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment