Skip to content

Instantly share code, notes, and snippets.

@SimplGy
Created August 12, 2013 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimplGy/6213749 to your computer and use it in GitHub Desktop.
Save SimplGy/6213749 to your computer and use it in GitHub Desktop.
Creates 1x and 2x background images. The 200% means that the pixel offsets will work on both the small and large images. Make sure your sprites line up exactly, so that the 2x images are exactly twice as big, twice as low, and twice as left.
//Support 1 and 2x image sizes
@mixin 2xBackground($url)
background-image: url($url + ".png")
@media only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3)
background-image: url($url + "@2x.png")
background-size: 200%
@SimplGy
Copy link
Author

SimplGy commented Aug 12, 2013

This only works if the bg image happens to be twice as large as the containing element, as is usually the case with sprite sheets that have a normal and hover state. The % is relative to the container, not the image size. Makes this less reusable/flexible than I thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment