Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any drawbacks to this CSS sprite solution for 'retina' displays?

My idea, assuming you start with a 200x200 sprite (meaning the double resolution image is 400x400) is this:

.sprite {
    background-image:url('1x.png');
    background-repeat: no-repeat;
    background-size: 200px 200px;
}

@media only screen and (-webkit-min-device-pixel-ratio: 2) {
    .sprite {
        background-image:url('2x.png');
    }
}

Live example: http://ov3rkill.com/temp/a5dii52/

I've struggled for a while trying to determine the best way to deliver higher resolutions images (previously I kept all images separate and sized them individually) and this frankly seems too simple.

Can anyone see any potential drawbacks? I'm toying with this for production use and so far it appears to work.

like image 963
4lun Avatar asked Oct 09 '22 02:10

4lun


1 Answers

Since the media query for retina is being called at load it should override the original call to load the small image. I've never witnessed the low-res image flashing in when using this method on retina displays.

Has anyone used JS to confirm that the smaller image loads on a retina display? I curious to know.

like image 72
The John Smith Avatar answered Oct 10 '22 14:10

The John Smith