Skip to content

Instantly share code, notes, and snippets.

@maggo
Last active August 29, 2015 14:15
Show Gist options
  • Save maggo/878d63414566c0769543 to your computer and use it in GitHub Desktop.
Save maggo/878d63414566c0769543 to your computer and use it in GitHub Desktop.
Mixin for centralized media query management in SCSS
/**
* Mediaquery collection, used to build responsive features.
*/
$mediaqueries:
small "only screen",
medium "only screen and (min-width: 768px)",
large "only screen and (min-width: 1024px)"
!default;
@mixin media($query-id) {
$check: null;
@each $mediaquery in $mediaqueries {
@if nth($mediaquery, 1) == $query-id {
$check: $query-id;
@media #{nth($mediaquery, 2)} {
@content;
}
}
}
@if not $check { @warn "Mediaquery #{id} is not defined." }
}
/**
* Usage:
* @include media('small') {
* //breakpoint here
* }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment