Last active
December 6, 2019 13:58
-
-
Save bugzbrown/8b8d242ed4a6858810c8fab89b5a7d65 to your computer and use it in GitHub Desktop.
SCSS Breakpoint 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 respond-to($breakpoint) { | |
// If the key exists in the map | |
@if map-has-key($breakpoints, $breakpoint) { | |
// Prints a media query based on the value | |
@media #{inspect(map-get($breakpoints, $breakpoint))} { | |
@content; | |
} | |
} | |
// If the key doesn't exist in the map | |
@else { | |
@warn "Unfortunately, no value could be retrieved from `#{$breakpoint}`. " | |
+ "Available breakpoints are: #{map-keys($breakpoints)}."; | |
} | |
} | |
/** BREAK POINTS FOR MEDIA QUERIES mobile first **/ | |
$breakpoints: ( | |
'tiny': only screen and ( max-width: 375px ), | |
'small': only screen and ( min-width: 415px ), | |
'medium': only screen and ( min-width: 768px ), | |
'large': only screen and ( min-width: 1024px ), | |
'xlarge': only screen and ( min-width: 1281px ), | |
) !default; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this, import it into your SCSS file and then whenever you want to add a breakpoint do as follows: