Last active
December 19, 2015 08:29
-
-
Save anasnakawa/5925634 to your computer and use it in GitHub Desktop.
generic media query mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------------------------ | |
// 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