Last active
December 29, 2016 17:06
-
-
Save VitorLuizC/fd1ff44b0f3f27bcad97ab61417b6dca to your computer and use it in GitHub Desktop.
CSS Breakpoints mixin for SASS + example usage
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
| $_BREAKPOINTS: ( | |
| print: print, | |
| xs: screen, // mobile-first fallback | |
| sm: 48rem, | |
| md: 64rem, | |
| lg: 75rem | |
| ) !global; | |
| @mixin breakpoint($point, $type: min) { | |
| @if (type-of($point) == string) { | |
| $point: map-get($_BREAKPOINTS, $point); | |
| @if ($point == null) { | |
| @error 'invalid breakpoint "#{$point}".'; | |
| } | |
| } | |
| $query: if(type-of($point) == number, '(#{$type}-width: #{$point})', $point); | |
| @media #{$query} { | |
| @content; | |
| } | |
| } | |
| // Usage | |
| // @include breakpoint(md) { | |
| // height: 3.125rem; | |
| // } | |
| // @include breakpoint(48.625rem, max) { // Custom breakpoint | |
| // height: calc(2rem + 2px); | |
| // border-width: 2px 0; | |
| // } | |
| // @include breakpoint(print) { | |
| // border-radius: unset; | |
| // } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment