Media queries Detailed

Source: Internet
Author: User

IPhone4

<link rel= "stylesheet" media= "only screens and (-webkit-min-device-pixel-ratio:2)" type= "Text/css" href= " Iphone4.css "/>
The above style is written specifically for IPhone4 mobile devices.

Pad

<link rel= "stylesheet" media= "All and (orientation:portrait)" href= "Portrait.css" type= "Text/css"/>
<link rel= "stylesheet" media= "All and (Orientation:landscape)" href= "Landscape.css" type= "Text/css"/>
In the case of large numbers, the safari on the mobile device is the same as on the iphone, but the difference is that the ipad declares a different direction, such as the example above, which uses PORTRAIT.CSS to render the page in Portrait (portrait);
Use LANDSCAPE.CSS to render the page in landscape (landscape).

Android

Width of/*240px */
<link rel= "stylesheet" media= "only screens and (max-device-width:240px)" href= "Android240.css" type= "Text/css"/>
Width of/*360px */
<link rel= "stylesheet" media= "only screens and (min-device-width:241px) and (max-device-width:360px)" href= " Android360.css "type=" Text/css "/>
Width of/*480px */
<link rel= "stylesheet" media= "only screens and (min-device-width:361px) and (max-device-width:480px)" href= " Android480.css "type=" Text/css "/>
We can use media query to provide specific styles for Android phones at different resolutions, so that the screen resolution can be resolved differently for Android phone page refactoring issues.

Not keyword

<link rel= "stylesheet" media= "not print and (max-width:1200px)" href= "Print.css" type= "Text/css"/>
The NOT keyword is used to exclude a certain type of media, in other words, to exclude devices that match an expression.

only keyword

<link rel= "stylesheet" media= "only screens and (max-device-width:240px)" href= "Android240.css" type= "Text/css"/>

Only used to set a specific media type that can be used to exclude browsers that do not support media queries. In fact, only many times it is used to hide style sheets for devices that do not support media query but support media type.

The main features are: devices that support media Queries, the normal invocation style, when only does not exist, and for devices that do not support media features (media Queries) but that support the medium type, which will not read the style,
Because its first reads only instead of screen, and the browser does not support media qqueries, the style will not be adopted, whether or not it supports only.

Other

If media Type is not explicitly specified in media query, it defaults to all, such as:
<link rel= "stylesheet" media= "(min-width:701px) and (max-width:900px)" href= "Medium.css" type= "Text/css"/>
There is also a comma (,) that is used to denote a juxtaposition or representation or, as follows
<link rel= "stylesheet" type= "Text/css" href= "Style.css" media= "handheld and (max-width:480px), screen and (min-width : 960px) "/>
The style.css style in the code above is used on a handheld device with a width less than or equal to 480px, or on a device with a screen width greater than or equal to 960px.

The output width of the device's screen is device width

<link rel= "stylesheet" media= "screen and (max-device-width:480px)" href= "Iphone.css" type= "Text/css"/>
The above code refers to the IPHONE.CSS style for the maximum device width of 480px, such as the display on the iphone, where Max-device-width refers to the actual resolution of the device, that is, the visual area resolution

Multiple Media queries use

<link rel= "stylesheet" media= "screen and (min-width:600px) and (max-width:900px)" href= "Style.css" type= "text/css"/ >
Media query can combine multiple media queries, in other words, a media query can contain between 0 and more expressions, and the expression can contain between 0 and more keywords, as well as a media Type.
As it says above, when the screen is between 600px-900px, the STYLE.CSS style is used to render the Web page.

One, max width max

<link rel= "stylesheet" media= "screen and (max-width:600px)" href= "Small.css" type= "Text/css"/>
The above indicates that when the screen is less than or equal to 600px, the Web page is rendered in the Small.css style.

@media Introduction

This type of introduction is the same as @import, and there are two ways:

Used in style files:

    1. @media screen{
    2. Selector {
    3. attribute: property value;
    4. }
    5. }

Called in <style>...</style> in

    1. <HEAD>
    2. <style type = "text/css" >
    3. @media Screen{
    4. selector {
    5. Span class= "pun" >
    6. }
    7. </STYLE>
    8. </HEAD>

@import approach introduced

@import introduced in two ways, one is to call a style file through @import in the style file, another method is introduced in

Another style file is called in the style file:

    1. @import url("Css/reset.css") screen;
    2. @import url("Css/print.css") print;

Called in <style>...</style> in

    1. <style type="Text/css">
    2. @import url("Css/style.css") all;
    3. </style>

XML approach introduced
    1. <? XML-stylesheet rel="stylesheet" Media="screen" href="css/ Style.css " ? >

The link method introduces

    1. <link rel="stylesheet" type="text/css" href=". /css/print.css " Media=" print " />

Media queries Detailed

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.