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

青灯夜游
青灯夜游Original
2021-04-06 18:42:232553browse

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 代码...;
 }

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.

Value Description
all is used for All media devices
print for printers
screen for computer screens, tablets , smartphones, etc.
speech for screen readers

Media Function

Value Description
aspect- ratio Define the ratio of the width and height of the visible area of ​​the page in the output device
color Define 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-index The 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-height Define the screen visible height of the output device.
device-width Define the visible width of the screen of the output device.
height Define 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-color Define 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-width Define the maximum visible width of the screen of the output device.
max-height Define the maximum visible area height of the page in the output device.
max-resolution Define the maximum resolution of the device.
max-width Define the maximum visible area width of the page in the output device.
min-device-width Define 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-height Define the minimum visible area height of the page in the output device.
min-width Define the minimum visible area width of the page in the output device.
orientation Defines whether the height of the visible area of ​​the page in the output device is greater than or equal to the width.
resolution Define 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;
    }
}

(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!

Statement:
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
Previous article:How to clear float in cssNext article:How to clear float in css