Skip to content

Instantly share code, notes, and snippets.

@anasnakawa
Last active December 19, 2015 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anasnakawa/5925634 to your computer and use it in GitHub Desktop.
Save anasnakawa/5925634 to your computer and use it in GitHub Desktop.
generic media query mixin
// ------------------------------
// generic media query mixin
// ------------------------------
// author: Anas Nakawa
// license: MIT
// ------------------------------
// table of content
// ------------------------------
// media-compact-retina (private)
// media-conpact-normal (private)
// media
// ------------------------------
// usage:
// @include media($min: 980px) { }
// @include media($max: 1200px) { }
// @include media($min: 980px, $isRetina: true) { }
// ------------------------------
// private mixin
@mixin media-compact-retina($min: 0, $max: null) {
@if $max == null {
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5) and (min-width: $min),
only screen and (min-device-pixel-ratio : 1.5) and (min-width: $min) {
@content;
}
} @else {
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5) and (min-width: $min) and (max-width: $max),
only screen and (min-device-pixel-ratio : 1.5) and (min-width: $min) and (max-width: $max) {
@content;
}
}
}
// private mixin
@mixin media-compact-normal($min: 0, $max: null) {
@if $max == null {
@media only screen and (min-width: $min) {
@content;
}
} @else {
@media only screen and (min-width: $min) and (max-width: $max) {
@content;
}
}
}
// generic purpose media query mixin
//
// * **param:** {dimension} $min [optional] minium width
// * **param:** {dimension} $max [optional] maximum width
// * **param:** {boolean} $isRetina [optional] should target retina displays ?
@mixin media($min: 0, $max: null, $isRetina: false) {
@if $isRetina == true {
@include media-compact-retina($min, $max) {
@content;
}
} @else {
@include media-compact-normal($min, $max) {
@content;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment