Last active
November 23, 2021 18:56
-
-
Save tylerpaige/d22a346c86f61d70b10318e5e61ec49c to your computer and use it in GitHub Desktop.
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
| :root { | |
| --gutter: 1rem; | |
| } | |
| @media screen and (min-width: 30rem) { | |
| :root { | |
| --gutter: 2rem; | |
| } | |
| } | |
| /* | |
| Applies spacing using multiples of the gutter. This mixin is responsive, in that `var(--gutter)` is a CSS variable that changes values with the viewport. | |
| @param {('padding'|'margin')} $kind what property should be used for the spacing | |
| @param {('top'|'right'|'bottom'|'vertical'|'horizontal'|'all')} $side where the spacing should be applied | |
| @param {number} $size how many units of space you want | |
| Example: | |
| .my-selector { | |
| @include space('margin', 'horizontal', 2); | |
| } | |
| */ | |
| @mixin space($kind, $side, $size: 1) { | |
| @if $kind and $side { | |
| $spacer: calc(var(--gutter) * #{$size}); | |
| @if $side == "all" { | |
| #{$kind}: $spacer; | |
| } @else if $side == "horizontal" { | |
| #{$kind}-left: $spacer; | |
| #{$kind}-right: $spacer; | |
| } @else if $side == "vertical" { | |
| #{$kind}-top: $spacer; | |
| #{$kind}-bottom: $spacer; | |
| } @else { | |
| #{$kind}-#{$side}: $spacer; | |
| } | |
| } @else { | |
| @warn "space mixin requires a kind (padding or margin) and a side."; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment