CSS3 multimedia queries
CSS3 Multimedia Query
CSS2 Multimedia Type
@media rules are introduced in CSS2, and different style rules can be customized for different media types.
For example: You can set different style rules for different media types (including monitors, portable devices, TVs, etc.).
But these multimedia types are not friendly enough to support on many devices.
CSS3 Multimedia Query
CSS3 multimedia query inherits all the ideas of CSS2 multimedia types: instead of looking for the type of device, CSS3 adaptive display according to the settings.
Media queries can be used to detect many things, such as:
The width and height of the viewport (window) The width and height of the device Orientation (smartphone landscape, portrait). Resolution
Currently, many devices such as Apple phones, Android phones, and tablets use multimedia queries.
Multimedia query syntax
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 not|only mediatype and (expressions) {
CSS-Code;
}
If the specified multimedia type matches the device type, the query result returns true , the document will display the specified style effect on the matching device.
Unless you use the not or only operators, all styles will adapt to display on all devices.
not: not is used to exclude certain specific devices, such as @media not print (non-printing device).
only: Used to specify a special media type. For mobile devices that support Media Queries, if the only keyword exists, the mobile device's web browser will ignore the only keyword and directly apply the style file based on the following expression. For devices that do not support Media Queries but are capable of reading Media Type web browsers, this style file will be ignored when the only keyword is encountered.
all: All devices, this should be seen often.
You can also use different style files on different media:
CSS3 Multimedia Type
重置浏览器窗口查看效果!
如果媒体类型屏幕的可视窗口宽度小于 480 px ,背景颜色将改变。