Detailed usage of media queries in CSS3

Source: Internet
Author: User
Tags min wrapper

Media queries can use different styles under different conditions to make the page different from the device to achieve different rendering effects

@media Media type and (media attributes) {your style}

Max width max-width

"Max-width" is one of the most commonly used features in media attributes, meaning that the style takes effect when the media type is less than or equal to the specified width. Such as:

CSS code copy content to clipboard

@media screen and (max-width:480px) {

. ads {

Display:none;

}

}

The above indicates that when the screen is less than or equal to 480px, the ad block (. ads) on the page is hidden.

Min width min-width

"Min-width", in contrast to "max-width", refers to a style that takes effect when the media type is greater than or equal to the specified width.

CSS code copy content to clipboard

@media screen and (min-width:900px) {

. wrapper{width:980px;}

}

The above indicates that the width of the container ". Wrapper" is 980px when the screen is greater than or equal to 900px.

Multiple media features use

When the screen is between 600px~900px, the body's background color is rendered as "#f5f5f5," as shown below.

CSS code copy content to clipboard

@media screen and (min-width:600px) and (max-width:900px) {

Body {background-color: #f5f5f5;}

}

Output width of device screen device

On smart devices such as the iphone, ipad, and so on, you can also set the appropriate style depending on the size of the screen device (or call the appropriate style file). Similarly, the "Min/max" corresponding parameters, such as "Min-device-width" or "max-device-width", can also be used for screen devices.

CSS code copy content to clipboard

  

The above code refers to the "IPHONE.CSS" style for the maximum device width of 480px, such as the iphone display, where the "max-device-width" refers to the actual resolution of the device, which refers to the visual area resolution.

Not keyword

CSS code copy content to clipboard

@media not print and (max-width:1200px) {style code}

The code above indicates that the style code will be used in all devices except the print device and device width of less than 1200px.

only keyword

CSS code copy content to clipboard

  

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.