Home > Web Front-end > CSS Tutorial > Detailed explanation of the actual use of @media in CSS3

Detailed explanation of the actual use of @media in CSS3

黄舟
Release: 2016-12-23 15:42:32
Original
2130 people have browsed it

This tutorial explains the actual use of @media in CSS3 in detail

Syntax:


CSS Code copies content to the clipboard

@media :<sMedia> { sRules }
Copy after login

Value:

<sMedia>:
    指定设备名称。
{sRules}:
    样式表定义。
Copy after login

Instructions:


Determine the media (object) type to achieve different presentations. This feature allows CSS to operate more accurately on different media types and different conditions of the same media (resolution, color number, etc.).

Copy code The code is as follows:

media_query: [only | not]? <media_type> [ and <expression> ]*
expression: ( <media_feature> [: <value>]? )
media_type: all | aural | braille | handheld | print | projection | screen | tty | tv | embossed
media_feature: width | min-width | max-width 
| height | min-height | max-height
| device-width | min-device-width | max-device-width
| device-height | min-device-height | max-device-height
| device-aspect-ratio | min-device-aspect-ratio | max-device-aspect-ratio
| color | min-color | max-color
| color-index | min-color-index | max-color-index
| monochrome | min-monochrome | max-monochrome 
| resolution | min-resolution | max-resolution
| scan | grid
Copy after login

Common writing:

CSS Code Copy content To the clipboard

@media screen and (max-width: 600px) { /*当屏幕尺寸小于600px时,应用下面的CSS样式*/  
  .class {   
    background: #ccc;   
  }   
}
Copy after login

@media screen and This is the most common way of writing, followed by a limited screen size

with all and only


Generally all and only appear together.


CSS Code copies content to the clipboard

@media all and (min-width:xxx) and (max-width:xxx){   
/*这段查询的all是针对所有设备(有些设备不一定是屏幕,也许是打字机,盲人阅读器)*/  
}
Copy after login
@media only screen and (min-width:xxx) and (max-width:xxx){   
/*上面针对了所有设备,这段是只(only)针对彩色屏幕设备*/  
}   
device-aspect-ratio
Copy after login

device-aspect-ratio can be used to adapt to devices with specific screen aspect ratios. This is also a very useful attribute. For example, our page wants Define a style for normal screens with an aspect ratio of 4:3, and then define another style for widescreens with an aspect ratio of 16:9 and 16:10, such as adaptive width and fixed width:

Usage:

CSS Code copies content to the clipboard

@media only screen and (device-aspect-ratio:4/3)
Copy after login

The above is the detailed explanation of the actual use of @media in CSS3. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template