Skip to content

Instantly share code, notes, and snippets.

@SimplGy SimplGy/2xBackground
Created Aug 12, 2013

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.