Last active
December 22, 2015 01:19
-
-
Save Matt-Jensen/6395680 to your computer and use it in GitHub Desktop.
A sass function to generate retina media queries.
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
/* Update: 5/3/14 - supports IE9+, FF3.5+, Opera9.5+ */ | |
@mixin retina($query: null, $density: 2) { | |
$dpi: $density * 96; | |
/* Accepts optional @media query conditions */ | |
@if $query { | |
$query: "and (#{$query})"; | |
} | |
@else { | |
$query: ""; | |
} | |
@media | |
#{"only screen " + $query + " and (-webkit-min-device-pixel-ratio: " + $density + ")"}, | |
#{"only screen " + $query + " and (min-resolution: " + $dpi + "dpi)"}, | |
#{"only screen " + $query + " and (min-resolution: " + $density + "dppx)"} { | |
@content; | |
} | |
} | |
/* " */ | |
/*** Basic Usage for targeting only 2dppx / 192dpi devices: ***/ | |
@include retina() { | |
.your-nifty-selector { | |
opacity: 1; | |
background: red | |
} | |
} | |
/*** Including additional @media query conditions with each density condition ***/ | |
@include retina("min-width: 640em", 1.5) { | |
.more-selector-fun { | |
color: red; | |
} | |
} | |
/*** Just changing device density query: ***/ | |
@include retina(null, 1.5) { | |
.more-selector-fun { | |
color: red; | |
} | |
} | |
/*** Using string interpolation to do cool stuff with Zurb's Foundation Framework: ***/ | |
@include retina("min-width: #{lower-bound($medium-range)}") { | |
.that-parameter-is-interpolated { | |
content: 'Holy Smokes!' | |
} | |
} | |
/* Based on code by Brett Jankord */ | |
/* http://www.brettjankord.com/2012/11/28/cross-browser-retinahigh-resolution-media-queries */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment