Skip to content

Instantly share code, notes, and snippets.

@rydurham
Created September 9, 2014 18:46
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 rydurham/9dde974dea12b355525a to your computer and use it in GitHub Desktop.
Save rydurham/9dde974dea12b355525a to your computer and use it in GitHub Desktop.
Sass Media Queries mixin
$breakpoints: (
'small' ( '( max-width: 616px )'),
'medium' ( '( min-width: 617px ) and (max-width: 1066px)'),
'large' ( '( min-width: 1067px )')
);
@mixin respond-to($name, $push: false) {
// If the key exists in the map
@if map-has-key($breakpoints, $name) {
// Prints a media query based on the value
@media #{map-get($breakpoints, $name)} {
@content;
}
}
// If the key doesn't exist in the map
// But $push is defined
// @else if $push != false {
// // Add the new breakpoint to the map
// $breakpoints: map-merge($breakpoints, ($name $push)) !global;
// // And re-call the mixin normally
// @include respond-to($name) {
// @content;
// }
// }
// If the key doesn't exist in the map
// And there is no push
@else {
// Just warn the user
@warn "Unfortunately, no value could be retrieved from `#{$name}`. "
+ "Please make sure it is defined in `$breakpoints` map. "
+ "Or pass the media query as a second parameter to add it to the map.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment