Use media query to adapt the background map to devices of different resolutions

Source: Internet
Author: User

With the diversification of Internet access, the tool that users choose to surf the internet is no longer just a PC, but can be a mobile phone or tablet computer. The question is how to adapt the Web to different resolutions, which poses a new challenge for front-end engineers, and one of the important things is how to make the image a good user experience at different resolutions .

Method overview

The media Query property in CSS3 allows us to use different CSS depending on the width of the browser, the pixel ratio of the device, and so on. Of course, it has some other usage, please refer to here for details.

Device-pixel-ratio is a query condition for media query that is used to obtain the pixel ratio of a device. Generally speaking, the value of iphone4/4s is 2, the high-resolution ANDRIOD device is 1.5, the general device is 1, with these conditions, we can provide different resolutions of the various devices of the picture.

Assume that the image is compatible with the above pixel ratio, showing a picture with a width height of 100px. First we need to prepare three images of different resolutions: when the normal pixel ratio is 1 o'clock, we load the normal picture 100px*100px, when the pixel ratio is 1.5, load the picture of 150px*150px, when the pixel ratio is 2.0, load the picture of 200px*200px.

Using media query We can write this:

You can view the demo with a different resolution device:

Http://tgideas.qq.com/demo/media_query/demo_01.htm

Use media query to adapt the background map to devices of different resolutions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.