Skip to content

Instantly share code, notes, and snippets.

@jasonkmccoy
Last active August 29, 2015 14:16
Show Gist options
  • Save jasonkmccoy/356ce76743a4dae2e040 to your computer and use it in GitHub Desktop.
Save jasonkmccoy/356ce76743a4dae2e040 to your computer and use it in GitHub Desktop.
Sass @media query mixin
// ----
// Sass (v3.3.12)
// Compass (v1.0.0.alpha.21)
// ----
// Breakpoints map
// @type Map
$breakpoints: (
// Regular breakpoints
"small": "(max-width: 500px)",
"medium": "(max-width: 700px)",
"large": "(max-width: 800px)",
"extra-large": "(max-width: 1280px)",
// reverse breakpoints
"reverse-small": "(min-width: 501px)",
"reverse-medium": "(min-width: 701px)",
"reverse-large": "(min-width: 801px)",
"reverse-extra-large": "(min-width: 1281px)",
// Exclusive breakpoints
"exclusive-small": "(max-width: 500px)",
"exclusive-medium": "(min-width: 501px) and (max-width: 800px)",
"exclusive-large": "(min-width: 801px) and (max-width: 1280px)",
// Extra breakpoints
"iOS": "(min-device-width: 768px) and (max-device-width: 1024px), (max-device-width: 480px)"
) !default;
// Enable/disable media queries
// @type Bool
$media-queries: true !default;
// Output a media query named after `$point`.
// @param {String} $point
// @requires $breakpoints
// @requires $media-queries
@mixin breakpoint($point) {
$query: map-get($breakpoints, $point);
@if not $query {
@warn "Oh shit! You are requesting an invalid breakpoint: `#{$point}`. :(";
}
@else if $media-queries {
@media #{$query} {
@content;
}
}
}
// Example Usage
test {
color: red;
@include breakpoint(small) {
color: blue;
}
@include breakpoint(iOS) {
color: purple;
}
}
@jasonkmccoy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment