Optimizing Website Background for Retina Display Using CSS3 Media Queries

Many new devices have double the pixel density of old devices. So you can use images twice in size for your websites background or content, in order to obtain a better looking design.

The best and easiest way is to use two background images, as shown in the image above, and display the correct image using CSS3 media queries.
Using this method the right image will be sued as the background image depending on weather the device is equipped with a retina screen or not.

Here is the code:


You will have your regular CSS declaration of the body background image:

    background: url ('background-image.png') repeat;

At the end of your CSS stylesheet you can then use this code:

 only screen and (-webkit-min-device-pixel-ratio: 2),
 only screen and (   min--moz-device-pixel-ratio: 2),
 only screen and (     -o-min-device-pixel-ratio: 2/1),
 only screen and (        min-device-pixel-ratio: 2),
 only screen and (                min-resolution: 192dpi),
 only screen and (                min-resolution: 2dppx) {
      background: url ('background-image@2x.png') repeat;

Please leave your questions or suggestions below.


Popular posts from this blog

How to create a PHP, Bootstrap 3 Contact Form which works with blogger and any other platform

You Can Now Download All My Music Free