Skip to content

Instantly share code, notes, and snippets.

@moxdev
Created August 10, 2016 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moxdev/9fce5efc4039bbcec2459240c78d1009 to your computer and use it in GitHub Desktop.
Save moxdev/9fce5efc4039bbcec2459240c78d1009 to your computer and use it in GitHub Desktop.
Mobile first mixin using the source map as the breakpoint
// https://www.sitepoint.com/managing-responsive-breakpoints-sass/
$breakpoints: (
'small' : ( min-width: 767px ),
'medium' : ( min-width: 992px ),
'large' : ( min-width: 1200px )
);
@mixin respond-to($name) {
// If the key exists in the map
@if map-has-key($breakpoints, $name) {
// Prints a media query based on the value
@media #{inspect(map-get($breakpoints, $name))} {
@content;
}
}
// If the key doesn't exist in the map
@else {
@warn "Unfortunately, no value could be retrieved from `#{$breakpoint}`. "
+ "Please make sure it is defined in `$breakpoints` map.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment