Last active
August 29, 2015 14:20
-
-
Save seafarer/0d3194fb2a1ec8d5c20d to your computer and use it in GitHub Desktop.
respond to mixin
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
$small-screen: 480px; | |
$medium-screen: 768px; | |
$large-screen: 960px; | |
$huge-screen: 1232px; | |
$breakpoints: ( | |
'small': ( max-width: $small-screen ), | |
'small-up': ( min-width: $small-screen ), | |
'medium': ( max-width: $medium-screen ), | |
'medium-up': ( min-width: $medium-screen ), | |
'large': ( max-width: $large-screen ), | |
'large-up': ( min-width: $large-screen ), | |
'huge': ( max-width: $huge-screen ) | |
); | |
@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