Skip to content

Instantly share code, notes, and snippets.

@jakebellacera
Created April 6, 2015 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebellacera/5d727153610f51caa9c5 to your computer and use it in GitHub Desktop.
Save jakebellacera/5d727153610f51caa9c5 to your computer and use it in GitHub Desktop.
simple 2x images in LESS
// Sets a 1x and a 2x background-image on an element.
//
// Arguments:
// @path - a String path to the 1x version of the image. The 2x version of this
// image must exist in the same directory as the 1x and have "_2x" at
// the end of its filename.
// @size - the value for the background-size attribute (e.g. 10px 20px; 100%).
.bg-image(@path, @size) {
background-image: url(@path);
background-size: @size;
@media (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (-webkit-min-device-pixel-ratio: 1.5), (min-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx){
background-image: replace(@path, "\.([a-zA-Z]{3,4})$", "_2x.$1");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment