1e41f4b71Sopenharmony_ci# Media Query
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci>  **NOTE**
4e41f4b71Sopenharmony_ci>
5e41f4b71Sopenharmony_ci>  - This API is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  - The **media** attribute uses the actual size, physical pixel, and screen resolution of the device by default.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ciMedia queries are widely used. You can use them to modify the application style based on the device type or specific features and device parameters (such as the screen resolution). Specifically, media queries allow you to design a layout style based on the device and application attributes.
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## CSS Syntax Rules
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciUse **@media** to import query statements. The rule is as follows:
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci@media [media-type] [and|or] [(media-feature)] {
19e41f4b71Sopenharmony_ci  CSS-Code;
20e41f4b71Sopenharmony_ci}
21e41f4b71Sopenharmony_ci```
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**@media screen and (round-screen: true) { … }**: The condition is met when the device screen is round.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**@media (max-height: 454) { … }**: Range query. CSS level 3 is used.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci>  **NOTE**
28e41f4b71Sopenharmony_ci>
29e41f4b71Sopenharmony_ci>  - The following operators are not supported: <=, >=, <, and >.
30e41f4b71Sopenharmony_ci>  - Nested parentheses are supported since API version 9.
31e41f4b71Sopenharmony_ci>  - A media query statement can contain a maximum of 512 characters.
32e41f4b71Sopenharmony_ci>  - A media query condition can contain a maximum of 32 characters.
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci## Media Type
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci| Type    | Description            |
38e41f4b71Sopenharmony_ci| ------ | -------------- |
39e41f4b71Sopenharmony_ci| screen | Media query based on screen-related parameters.|
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci## Media Logical Operation
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ciYou can use media logical operators to implement complex media query. The following table describes the available operators.
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci**Table 1** Media logical operators
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci| Type             | Description                                      |
49e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------- |
50e41f4b71Sopenharmony_ci| and             | The **and** operator is used to combine multiple media features into one media query, in a logical AND operation. The query is valid only when all media features are true. It can also combine media types and media functions.<br>For example, **screen and (device-type: liteWearable) and (max-height: 454)** evaluates to **true** when the device type is wearable and the maximum height of the application is 454 pixel units.|
51e41f4b71Sopenharmony_ci| or<sup>9+</sup> | The **or** operator is used to combine multiple media features into one media query, in a logical OR operation. The query is valid if a media feature is true.<br>For example, **screen and (max-height: 454) or (round-screen: true)** evaluates to **true** when the maximum height of the application is 454 pixel units or the device screen is round.|
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci## Media Features
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci| Type              | Description                                      |
59e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- |
60e41f4b71Sopenharmony_ci| height           | Height of the display area on the application page.                            |
61e41f4b71Sopenharmony_ci| min-height       | Minimum height of the display area on the application page.                          |
62e41f4b71Sopenharmony_ci| max-height       | Maximum height of the display area on the application page.                          |
63e41f4b71Sopenharmony_ci| width            | Width of the display area on the application page.                            |
64e41f4b71Sopenharmony_ci| min-width        | Minimum width of the display area on the application page.                          |
65e41f4b71Sopenharmony_ci| max-width        | Maximum width of the display area on the application page.                          |
66e41f4b71Sopenharmony_ci| aspect-ratio     | Ratio of the width to the height of the display area on the application page.<br>Example: **aspect-ratio: 1/2**|
67e41f4b71Sopenharmony_ci| min-aspect-ratio | Minimum ratio of the width to the height of the display area on the application page.                    |
68e41f4b71Sopenharmony_ci| max-aspect-ratio | Maximum ratio of the width to the height of the display area on the application page.                    |
69e41f4b71Sopenharmony_ci| round-screen     | Screen type. The value **true** means that the screen is round, and **false** means the opposite.|
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci## Sample Code for the Common Media Feature
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciThe number and type of attributes must be the same among **.container** blocks. Otherwise, display errors will occur.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci```html
77e41f4b71Sopenharmony_ci<!-- xxx.hml -->
78e41f4b71Sopenharmony_ci<div>
79e41f4b71Sopenharmony_ci  <div class="container">
80e41f4b71Sopenharmony_ci    <text class="title">Hello World</text>
81e41f4b71Sopenharmony_ci  </div>
82e41f4b71Sopenharmony_ci</div>
83e41f4b71Sopenharmony_ci```
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci```css
86e41f4b71Sopenharmony_ci/* xxx.css */
87e41f4b71Sopenharmony_ci.container {
88e41f4b71Sopenharmony_ci  width: 300px;
89e41f4b71Sopenharmony_ci  height: 600px;
90e41f4b71Sopenharmony_ci  background-color: #008000;
91e41f4b71Sopenharmony_ci}
92e41f4b71Sopenharmony_ci.title {
93e41f4b71Sopenharmony_ci    font-size: 30px;
94e41f4b71Sopenharmony_ci    text-align: center;
95e41f4b71Sopenharmony_ci}
96e41f4b71Sopenharmony_ci@media (device-type: samrtVision) {
97e41f4b71Sopenharmony_ci  .container {
98e41f4b71Sopenharmony_ci    width: 500px;
99e41f4b71Sopenharmony_ci    height: 500px;
100e41f4b71Sopenharmony_ci    background-color: #fa8072;
101e41f4b71Sopenharmony_ci  }
102e41f4b71Sopenharmony_ci} 
103e41f4b71Sopenharmony_ci@media (device-type: liteWearable) {
104e41f4b71Sopenharmony_ci  .container {
105e41f4b71Sopenharmony_ci    width: 300px;
106e41f4b71Sopenharmony_ci    height: 300px;
107e41f4b71Sopenharmony_ci    background-color: #008b8b;
108e41f4b71Sopenharmony_ci  }
109e41f4b71Sopenharmony_ci} 
110e41f4b71Sopenharmony_ci```
111