Skip to content

Instantly share code, notes, and snippets.

@zthornto
Last active December 30, 2015 10:29
Show Gist options
  • Save zthornto/d68af592458515bfcb8a to your computer and use it in GitHub Desktop.
Save zthornto/d68af592458515bfcb8a to your computer and use it in GitHub Desktop.
Retina Images Mixin
//create mixin to handle scaling of retina images
@mixin image-2x($image, $width, $height) {
@media (min--moz-device-pixel-ratio: 1.3),
(-o-min-device-pixel-ratio: 2.6/2),
(-webkit-min-device-pixel-ratio: 1.3),
(min-device-pixel-ratio: 1.3),
(min-resolution: 1.3dppx) {
background-image: url($image);
background-size: $width $height;
}
}
.element {
//non-retina image
background:url('images/sample.png') center center no-repeat;
//retina image: src, rendered width, rendered height (these are the dimensions of the non-retina sized image)
@include image-2x("images/sample2x.png", 15px, 14px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment