Created
April 6, 2015 19:13
-
-
Save jakebellacera/5d727153610f51caa9c5 to your computer and use it in GitHub Desktop.
simple 2x images in LESS
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
// 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