Skip to content

Instantly share code, notes, and snippets.

@soutar
Created October 14, 2014 14:47
Show Gist options
  • Save soutar/4b03e8095f51640d6357 to your computer and use it in GitHub Desktop.
Save soutar/4b03e8095f51640d6357 to your computer and use it in GitHub Desktop.
Retina background image mixin for LESS
// Set the background image for retina devices
.background-image-retina(@url, @ext, @width, @height) {
@lowres: "@{url}.@{ext}";
@highres: "@{url}@2x.@{ext}";
background-image: url(@lowres);
background-size: @width @height;
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
background-image: url(@highres);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment