8.21. CSS3 multimedia query

发布时间 :2024-01-18 23:00:05 UTC      

8.21.1. CSS2 multimedia type

@media rules are described 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, televisions, etc.).

But these multimedia types are not friendly enough to support on many devices.

8.21.2. CSS3 multimedia query

CSS3’s multimedia query inherits all the ideas of CSS2 multimedia type: instead of finding the type of device, CSS3 displays adaptively according toits settings.

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

  • Width and height of viewport (window)

  • Width and height of the equipment

  • Facing (smartphone horizontal screen, vertical screen).

  • Resolution

At present, many devices such as Apple phones, Android phones, tablets and so on use multimedia queries.

8.21.3. Browser support

The number in the table represents the version number of the first browser that supports the property.

Attribute

@ media

21.0

9.0

3.5

4.0

9.0

8.21.4. Multimedia query syntax

A multimedia query consists of multiple media and can contain one or more expressions, which are returned according to whether the condition is true or not true or false .

@medianot\|onlymediatypeand(expressions){CSS code...;}

If the specified multimedia type matches the device type, the query result is returned. The true document displays the effect of the specified style on the matching device

Unless you use not or only operator, otherwise all styles will be adapted to display on all devices.

  • not : not is used to exclude certain devices, such as @media not print (non-printing device).

  • only :Used to determine a particular type of media. For mobile devices that support Media Queries, if there is only keyword, the Web browser of the mobile device ignores the only keyword and apply the style file directly based on the following expression. For Web browsers that do not support Media Queries but can read Media Type types, encountered only keyword, this style file is ignored.

  • all : all the equipment, this should be seen frequently.

You can also use different style files on different media:

<linkrel="stylesheet"media="mediatypeand\|not\|only(expressions)"href="print.css">

8.21.5. CSS3 multimedia type

Value

Description

All

For all multimedia types of Devic

Print

For printers

Screen

For computer screens, tablets, smartphones and so on.

Speech

For screen readers

8.21.6. A simple example of multimedia query

Using multimedia queries, you can replace the original style with the corresponding style on the specified device.

The following example modifies the background color on a device with a screen visual window size of less than 480 pixels:

Example

@media screen and (max-width: 480px) {
    body {
        background-color: lightgreen;
    }
}

The following example floats the menu to the left side of the page when the size of the screen visual window is greater than 480 pixels:

Example

@media screen and (min-width: 480px) {
    #leftsidebar {width: 200px; float: left;}
    #main {margin-left:216px;}
}

The following example sets the screen visual window when the size is less than 600 pixels div element hiding:

Example

@media screen and (max-width: 600px) {
  div.example {
    display: none;
  }
}

8.21.7. CSS3 @media reference

For more multimedia queries, please refer to @media rules.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.