Skip to content

Instantly share code, notes, and snippets.

@krambuhl
Created September 28, 2015 22:44
Show Gist options
  • Save krambuhl/6136d801fceb58690cb6 to your computer and use it in GitHub Desktop.
Save krambuhl/6136d801fceb58690cb6 to your computer and use it in GitHub Desktop.
// create media queries from min/max
@mixin respond($min: 0, $max: null, $media: screen) {
@if $min > 0 and $max {
@include respond-between($min, $max, $media) { @content };
} @else if $min == 0 and $max {
@include respond-below($max, $media) { @content };
} @else if $min and $max == null {
@include respond-above($min, $media) { @content };
}
}
@mixin respond-between($min: null, $max: null, $media: screen) {
$max: $max - 1; // subtract 1 from max so (0, 720) and (720) dont overlap
$query: "only " + $media + " and (min-width: " + $min + ") and (max-width: " + $max + ")";
@media #{$query} { @content; };
}
@mixin respond-below($max: null, $media: screen) {
$query: "only " + $media + " and (max-width: " + $max + ")";
@media #{$query} { @content; };
}
@mixin respond-above($min: null, $media: screen) {
$query: "only " + $media + " and (min-width: " + $min + ")";
@media #{$query} { @content; };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment