CSS3 matches the screen status, while CSS3 matches the screen status.

Source: Internet
Author: User

CSS3 matches the screen status, while CSS3 matches the screen status.

@ Media is defined in css3 and has powerful functions. The following describes whether to use @ media orientation of css3 to match the screen of a mobile phone.

As the name suggests, the PC cannot match the landscape, so orientation only works for mobile devices.

1. header Declaration
<Meta name = "viewport" content = "width = device-width, initial-scale = 1.0, user-scalable = no, maximum-scale = 1.0">

Add to


2. Whether the media matching screen is a horizontal screen or a vertical screen
@ Media all and (orientation: landscape ){

/* This is the css code that matches the landscape screen */
Body {

}
}
@ Media all and (orientation: portrait ){

/* This is the css code that matches the portrait status */
Body {

}
}

3. Application location

(1) The content of the mobile WEB page is generally defined by percentage, so that the content can be displayed normally under different resolution devices, however, the screen resolution width and height of a mobile device are quite different. When the screen is flipped over, the width of the elements defined by the percentage may become very large, in this way, the page aesthetics will be lost. In this way, if orientation matches the screen flip status, you can write different css to control the page style.

(2) For mobile WEB pages with background images, you can set different background based on orientation to match the screen status.

(3) A little technical: some WEB pages with absolute positioning elements locate an element at the bottom of the page. When the screen is in the portrait status, it may be because the total length of the page is smaller than the screen height (but greater than the screen width), it is correct to position the absolute positioning element to the bottom, but when the screen is turned into a horizontal screen, in this case, because the page content height is greater than the screen height (that is, the screen width when the page is not flipped), the absolute positioning element will overwrite the page content, resulting in page problems. In this case, orientation can be used to match the screen status, adjust the css code.

You can also use JS to determine the status of the matching screen. In js, onorientationchange is an event of window. You can monitor the event to match the screen landscape and landscape.

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.