Skip to content

Instantly share code, notes, and snippets.

@AdmireNL
Last active August 29, 2015 14:09
Show Gist options
  • Save AdmireNL/52bd61e193d447cf2f94 to your computer and use it in GitHub Desktop.
Save AdmireNL/52bd61e193d447cf2f94 to your computer and use it in GitHub Desktop.
Media queries mixin
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
@mixin mq($min-max, $exclude: false) {
@if ($exclude and length($exclude == 2)) {
@media (min-width: nth($min-max,1)) and (max-width: nth($exclude,1)), (min-width: nth($exclude,2)) and (max-width: nth($min-max,2)) {
@content;
}
} @else {
@media (min-width: nth($min-max,1)) and (max-width: nth($min-max,2)) {
@content;
}
}
}
.foo {
@include mq(100px 500px) {
// This should output:
// @media (min-width: 100px) and (max-width: 500px)
zoom: 1;
}
@include mq($min-max: 100px 500px, $exclude: 200px 250px) {
// This should output:
// @media (min-width: 100px) and (max-width: 200px), (min-width: 250px) and (max-width: 500px)
zoom: 1;
}
}
@media (min-width: 100px) and (max-width: 500px) {
.foo {
zoom: 1;
}
}
@media (min-width: 100px) and (max-width: 200px), (min-width: 250px) and (max-width: 500px) {
.foo {
zoom: 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment