Skip to content

Instantly share code, notes, and snippets.

@jgillman
Forked from twe4ked/input.scss
Created July 2, 2012 21:40
Show Gist options
  • Save jgillman/3035882 to your computer and use it in GitHub Desktop.
Save jgillman/3035882 to your computer and use it in GitHub Desktop.
FREE! Sass (SCSS) mixin for including retina images in Webkit and Mozilla browsers.
@mixin background-image-retina($file, $type, $width, $height:$width) {
background-image: url($file + '.' + $type);
@media all and (-webkit-min-device-pixel-ratio: 2), all and (-moz-min-device-pixel-ratio: 2) {
& {
background-image: url($file + '@2x.' + $type);
-webkit-background-size: $width $height;
-moz-background-size: $width $height;
background-size: $width $height;
}
}
}
// Example
#foo {
@include background-image-retina('foobar', 'png', 10px, 20px);
background: repeat;
}
// Or if your image is square:
#bar {
@include background-image-retina('bazqux', 'png', 10px);
}
#foo {
background-image: url("foobar.png");
background: repeat; }
@media all and (-webkit-min-device-pixel-ratio: 2), all and (-moz-min-device-pixel-ratio: 2) {
#foo {
background-image: url("foobar@2x.png");
-webkit-background-size: 10px 20px;
-moz-background-size: 10px 20px;
background-size: 10px 20px; } }
#bar {
background-image: url("bazquz.png");
background: repeat; }
@media all and (-webkit-min-device-pixel-ratio: 2), all and (-moz-min-device-pixel-ratio: 2) {
#bar {
background-image: url("bazqux@2x.png");
-webkit-background-size: 10px 10px;
-moz-background-size: 10px 10px;
background-size: 10px 10px; } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment