delete src-attribute with CSS and replace with bg-image

On high-density devices like the new iPad you can replace an image by a high-desity image in the background.

by Jens Grochtdreis

HTML

<h2>Outside high-desity devices this is a cat</h2>
<img id="replace" src="http://placekitten.com/300/200">

<h2>This is the replacement image</h2>
<img src="http://placedog.com/600/400">

CSS

@media only screen and (-webkit-min-device-pixel-ratio: 2),
       only screen and (-moz-min-device-pixel-ratio: 2),
       only screen and (-o-min-device-pixel-ratio: 2/1),
       only screen and (min-device-pixel-ratio: 2) {
    img#replace {
        content: ""; 
        background-image: url("http://placedog.com/600/400"); 
        width: 300px; 
        height: 200px; 
        background-size: contain; 
        display: inline-block;  /* iOS-Safari needs this */
    }
}

h2 { margin: 30px 0;}

/* styling basics */
html {padding: 20px 0; background-color: #efefef;}
body {width: 80%; padding: 40px; margin: 0 auto; background: #fff; box-shadow: 1px 1px 5px rgba(0,0,0,0.5); font-family: Verdana, Arial, sans-serif; font-size: 14px;}