Home > Web Front-end > CSS Tutorial > What is the grammatical composition of media queries in css3

What is the grammatical composition of media queries in css3

青灯夜游
Release: 2023-01-04 09:34:40
Original
2550 people have browsed it

The syntax of media query is "@media not|only mediatype and (expressions) {CSS code...;}"; media query can be composed of multiple media and can contain one or more expressions. The expression returns true or false depending on whether the condition is true.

What is the grammatical composition of media queries in css3

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

CSS3's multimedia queries inherit all the ideas of CSS2 multimedia types: instead of looking for device types, CSS3 displays adaptively according to settings.

Media queries can be used to detect many things, such as:

  • The width and height of the viewport(window)

  • The device Width and height

  • Orientation (horizontal screen, vertical screen of smartphone)

  • Resolution

Currently, many devices such as Apple phones, Android phones, tablets, etc. use multimedia queries.

Query syntax

@media not|only mediatype and (expressions) {
    CSS 代码...;
 }
Copy after login

Multimedia query consists of a variety of media and can contain one or more expressions. The expression is based on whether the condition is true. Returns true or false.

Media type

#If the specified multimedia type matches the device type, the query result returns true, and the document will be on the matching device Display the specified style effect.

Unless the not or only operators are used, all styles will adapt to display on all devices.

ValueDescription
all is used for All media devices
printfor printers
screenfor computer screens, tablets , smartphones, etc.
speechfor screen readers

Media Function

ValueDescription
aspect- ratioDefine the ratio of the width and height of the visible area of ​​the page in the output device
colorDefine the number of color originals in each set of the output device . If it is not a color device, the value is equal to 0
color-indexThe number of entries defined in the output device's color lookup table. If no color lookup table is used, the value is equal to 0
device-aspect-ratio Defines the ratio of the visible width to height of the screen of the output device.
device-heightDefine the screen visible height of the output device.
device-widthDefine the visible width of the screen of the output device.
heightDefine the height of the visible area of ​​the page in the output device.
max-aspect-ratio Defines the maximum ratio of the output device's screen visible width to height.
max-colorDefine the maximum number of color originals in each group of output devices.
max-color-index Defines the maximum number of entries in the output device's color lookup table.
max-device-aspect-ratio Defines the maximum ratio of the output device's screen visible width to height.
max-device-height Defines the maximum height visible on the screen of the output device.
max-device-widthDefine the maximum visible width of the screen of the output device.
max-heightDefine the maximum visible area height of the page in the output device.
max-resolutionDefine the maximum resolution of the device.
max-widthDefine the maximum visible area width of the page in the output device.
min-device-widthDefine the minimum visible width of the screen of the output device.
min-device-height Defines the minimum visible height of the screen of the output device.
min-heightDefine the minimum visible area height of the page in the output device.
min-widthDefine the minimum visible area width of the page in the output device.
orientationDefines whether the height of the visible area of ​​the page in the output device is greater than or equal to the width.
resolutionDefine the resolution of the device. For example: 96dpi, 300dpi, 118dpcm
width Define the width of the visible area of ​​the page in the output device.

For example
The screen width is greater than 480px, and the font size is set to 16px.

@media screen and (min-width: 480px) {
    body {
       font-size:16px;
    }
}
Copy after login

(Learning video sharing: css video tutorial)

The above is the detailed content of What is the grammatical composition of media queries in css3. For more information, please follow other related articles on the PHP Chinese website!

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