Skip to content

Instantly share code, notes, and snippets.

@natecavanaugh
Created August 21, 2014 14:45
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 natecavanaugh/28eeb2a97b15801fa11a to your computer and use it in GitHub Desktop.
Save natecavanaugh/28eeb2a97b15801fa11a to your computer and use it in GitHub Desktop.
$breakpoint_phone: 768px !default;
$breakpoint_tablet: 980px !default;
@mixin respond-to($types...) {
$maxWidth: -1;
$minWidth: -1;
@each $type in $types {
@if $type == phone {
$maxWidth: if($maxWidth == -1, $breakpoint_phone - 1, $maxWidth);
$minWidth: 0;
}
@else if $type == tablet {
@if $maxWidth != 0 {
$maxWidth: if($maxWidth == -1, $breakpoint_tablet - 1, max($breakpoint_tablet - 1, $maxWidth));
}
$minWidth: if($minWidth == -1, $breakpoint_phone, min($breakpoint_phone, $minWidth));
}
@else if $type == desktop {
$maxWidth: 0;
$minWidth: if($minWidth == -1, $breakpoint_tablet, $minWidth);
}
}
@if $maxWidth <= 0 and $minWidth <= 0 {
@content;
}
@else if $maxWidth <= 0 {
@media (min-width: $minWidth) {
.responsive {
@content;
}
}
}
@else if $minWidth <= 0 {
@media (max-width: $maxWidth) {
.responsive {
@content;
}
}
}
@else {
@media (min-width: $minWidth) and (max-width: $maxWidth) {
.responsive {
@content;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment