Last active
December 16, 2015 08:29
-
-
Save adamjohnson/5406454 to your computer and use it in GitHub Desktop.
Painless retina images in Sass. Requires Compass.
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
// Painless Retina Images: | |
// ======================= | |
// https://gist.github.com/adamjohnson/5406454 | |
// http://blog.andrewckor.com/post/43347215341/retina-background-images-sass-mixin | |
// Requires Compass | |
// Suffix retina imagery with "@2x" & put in the same directory as normal assets (or specifiy a different directory in the @include) | |
@mixin bg-with-retina( $path, $img, $filetype, $size ) { | |
background-image: image-url( $path + $img + '.' + $filetype ); | |
@include background-size( $size ); | |
@media print, | |
(-o-min-device-pixel-ratio: 5/4), | |
(-webkit-min-device-pixel-ratio: 1.25), | |
(min-resolution: 120dpi) { | |
& { | |
background-image: image-url($path + $img + '@2x' + '.' + $filetype); | |
} | |
} | |
} | |
// Usage example: | |
// .cool { | |
// width: 150px; | |
// height: 40px; | |
// @include bg-with-retina( 'images/', 'cool', 'png', 150px 40px ); // FORMAT: (1)path, (2)image name, (3)file type, (4)width, (5)height | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment