<media_query_list>:[<media_query>[',' <media_query>]*]?
<media_query>:[only | not]? <media_type> [and <expression>]* | <expression> [and <expression>]*
<expression>:'('<media_feature>[:<value>]?')'
min和max用于表達“大于或等于”和“小與或等于”。如:width會有min-width和max-width媒體查詢可以被用在CSS中的@media和@import規則上,也可以被用在HTML和XML中。
示例代碼:
@media screen and (width:800px){ … } @import url(example.css) screen and (width:800px); <link media="screen and (width:800px)" rel="stylesheet" href="example.css" /> <?xml-stylesheet media="screen and (width:800px)" rel="stylesheet" href="example.css" ?>
| 媒體特性 | 取值 | 接受min/max | 描述 |
|---|---|---|---|
| width | <length> | yes | 定義輸出設備中的頁面可見區域寬度 |
| height | <length> | yes | 定義輸出設備中的頁面可見區域高度 |
| device-width | <length> | yes | 定義輸出設備的屏幕可見寬度 |
| device-height | <length> | yes | 定義輸出設備的屏幕可見高度 |
| orientation | portrait | landscape | no | 定義'height'是否大于或等于'width'。值portrait代表是,landscape代表否 |
| aspect-ratio | <ratio> | yes | 定義'width'與'height'的比率 |
| device-aspect-ratio | <ratio> | yes | 定義'device-width'與'device-height'的比率。如常見的顯示器比率:4/3, 16/9, 16/10 |
| color | <integer> | yes | 定義每一組輸出設備的彩色原件個數。如果不是彩色設備,則值等于0 |
| color-index | <integer> | yes | 定義在輸出設備的彩色查詢表中的條目數。如果沒有使用彩色查詢表,則值等于0 |
| monochrome | <integer> | yes | 定義在一個單色框架緩沖區中每像素包含的單色原件個數。如果不是單色設備,則值等于0 |
| resolution | <resolution> | yes | 定義設備的分辨率。如:96dpi, 300dpi, 118dpcm |
| scan | progressive | interlace | no | 定義電視類設備的掃描工序 |
| grid | <integer> | no | 用來查詢輸出設備是否使用柵格或點陣。只有1和0才是有效值,1代表是,0代表否 |
| 支持版本\類型 | IE | Firefox | Safari | Chrome | Opera |
|---|---|---|---|---|---|
| 版本 | 6-8 | 4 | 5.1.7 | 13 | 11.5 |
| 版本 | 9 |