by Artem Trgtsin
specifies how a physical display pixel compares to a pixel on a “normal” density screen
<meta name="viewport" content="
initial-scale=1,
maximum-scale=1">
function isRetina(){
return (('devicePixelRatio' in window &&
devicePixelRatio > 1) ||
('matchMedia' in window &&
!matchMedia("(-moz-device-pixel-ratio:1.0)").matches))
}
@media(-webkit-min-device-pixel-ratio:1.5),
(min--moz-device-pixel-ratio:1.5),
(-o-min-device-pixel-ratio:3/2),
(min-resolution:1.5dppx) {
E { something }
}
E {
background:url(50px.png) no-repeat;
}
@media (retina) {
E { background:url(100px.png) no-repeat; }
}
.location {background: url(sprite.png) no-repeat0 0; }
....
.fav-link {background: url(sprite.png) no-repeat0 -100px;}
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min-device-pixel-ratio: 2) {
.location,....,.fav-link {
background-image: url(sprite@2x.png);
background-size: 200px 200px;
}
}
<img src="example.svg" data-png-fallback="example.png" />
$(document).ready(function(){
if(!Modernizr.svg) {
var images = $('img[data-png-fallback]');
images.each(function(i) {
$(this).attr('src', $(this).data('png-fallback'));
});
}
});
E {
background:url(image.png) no-repeat;
background:
rgba(0, 0, 0, 0)
url(image.svg) no-repeat;
}
<img src="logo.svg" width="512" height="512">
<img src="logo.svg" width="256" height="256">
<img src="logo.svg" width="128" height="128">
<img src="logo.svg" width="32" height="32">
<img src="logo.svg" width="16" height="16">
<image id="icon-16" xlink:href="data…
<image id="icon-32" xlink:href="data…
<image id="icon-128" xlink:href="data…
<image id="icon-256" xlink:href="data…
<image id="icon-512" xlink:href="data…
#icon-16, #icon-32, #icon-128,
#icon-256, #icon-512 {
display:none;
}
@media screen and (width:16px) {
#icon-16 { display:inline }
}
<script type="text/javascript" src="/scripts/retina.js">
#logo {.at2x('/images/my_image.png', 200px, 100px);}
Will compile to:
#logo { background-image: url('/images/my_image.png'); }
@media all and (-webkit-min-device-pixel-ratio: 1.5) {
#logo {
background-image: url('/images/my_image@2x.png');
background-size: 200px 100px;
}
}
E {
background-image:url(picture.png);
background-image:image-set(
url(small.jpg) 1x,
url(medium.jpg) 2x);
}