CSS Media Query

Source: Internet
Author: User

First, a snippet of code:

<! DOCTYPE html>

The top uses the CSS media query, the browser will vary depending on the viewport, to change the body color: Media query allows us to set the corresponding style according to the various features of the device. In addition to this, you can use the @import directive to introduce other style sheets conditionally in the current style sheet. @import url ("phone.css") screen and (max-width:768px). [!!!: @import of CSS will increase HTTP requests].

What features can be detected by media queries:

The most commonly used is width (viewport width) device-width (screen width)

In addition, there are: orientation (check the device landscape or portrait) Aspect-ratio (based on the viewport aspect ratio.) A 16:9 scale display can be ASPECT-RATIO:16/9 like this) Device-aspect-ratio (similar to Aspect-ratio. such as Typically, Max-device-width is used for mobile device users, and Max-width is used for PC device users.

Use media queries to transform our design:

CSS represents cascading style sheets, that is, the style sheet behind the style will overwrite the front of the style, so we can first for the large viewport design, and then use the media query rewrite.

The best way to load media queries:

@media screen and (max-width:768px) {}. Respond.js adds media queries for IE8 and earlier, but does not support @import. If you use link, you will increase the number of HTTP requests.

Content reference to: Responsive web design HTML5 and CSS3 combat.

CSS Media Query

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.