Skip to content

Instantly share code, notes, and snippets.

@souporserious
Created March 31, 2016 02:38
Show Gist options
  • Save souporserious/308db0e4ffb2c6f85a3ac16cdf24049a to your computer and use it in GitHub Desktop.
Save souporserious/308db0e4ffb2c6f85a3ac16cdf24049a to your computer and use it in GitHub Desktop.
$breakpoints: (
sm: (0em, 40em),
md: (40.063em, 64em),
lg: (64.063em, 90em)
);
@function lower-bound($range){
@if length($range) <= 0 {
@return 0;
}
@return nth($range, 1);
}
@function upper-bound($range) {
@if length($range) < 2 {
@return 999999999999;
}
@return nth($range, 2);
}
@function add-breakpoint($key, $value) {
@return map-merge($breakpoints, ($key: $value));
}
@function get-query($breakpoint) {
@if map-has-key($breakpoints, $breakpoint) {
@return map-get($breakpoints, $breakpoint);
}
@warn "Unknown `#{$breakpoint}` in $breakpoints.";
@return null;
}
@mixin add-breakpoint($name, $bounds) {
$breakpoints: add-breakpoint($name, $bounds) !global;
}
@mixin add-bp($name, $bounds) {
@include add-breakpoint($name, $bounds);
}
@mixin above($breakpoint) {
$query: get-query($breakpoint);
@media screen and (min-width: #{upper-bound($query)}) {
@content
}
}
@mixin below($breakpoint) {
$query: get-query($breakpoint);
@media screen and (max-width: #{lower-bound($query)}) {
@content
}
}
@mixin when($breakpoint) {
$query: get-query($breakpoint);
@media screen and (min-width: #{lower-bound($query)}) and (max-width: #{upper-bound($query)}) {
@content
}
}
@mixin except($breakpoint) {
$query: get-query($breakpoint);
@media not screen and (min-width: #{lower-bound($query)}) and (max-width: #{upper-bound($query) - 0.01}) {
@content
}
}
@include add-breakpoint(module, (540px, 960px));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment