Skip to content

Instantly share code, notes, and snippets.

@cmpscabral
Created April 14, 2016 09:57
Show Gist options
  • Save cmpscabral/a50e07d1a0d5091a95a9176843bceb2f to your computer and use it in GitHub Desktop.
Save cmpscabral/a50e07d1a0d5091a95a9176843bceb2f to your computer and use it in GitHub Desktop.
media queries for retina displays
/* @2x Images (Pixel Ratio of 1.25+) */
@mixin image-2x($image, $width, $height) {
@media only screen and (min--moz-device-pixel-ratio: 5/4),
only screen and (-o-min-device-pixel-ratio: 5/4),
only screen and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (min-device-pixel-ratio: 1.25),
only screen and (min-resolution: 1.25dppx) {
background-image: url($image);
background-size: $width $height;
}
}
/* @3x Images (Pixel Ratio of 2.25+) */
@mixin image-3x($image, $width, $height) {
@media only screen and (min--moz-device-pixel-ratio: 9/4),
only screen and (-o-min-device-pixel-ratio: 9/4),
only screen and (-webkit-min-device-pixel-ratio: 2.25),
only screen and (min-device-pixel-ratio: 2.25),
only screen and (min-resolution: 2.25dppx) {
background-image: url($image);
background-size: $width $height;
}
}
/* @4x Images (Pixel Ratio of 3.25+) */
@mixin image-4x($image, $width, $height) {
@media only screen and (min--moz-device-pixel-ratio 13/4),
only screen and (-o-min-device-pixel-ratio: 13/4),
only screen and (-webkit-min-device-pixel-ratio: 3.25),
only screen and (min-device-pixel-ratio: 3.25),
only screen and (min-resolution: 3.25dppx) {
background-image: url($image);
background-size: $width $height;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment