@media:<media_query_list>
<media_query_list>:[<media_query>[',' <media_query>]*]?
<media_query>:[only | not]? <media_type> [and <expression>]* | <expression> [and <expression>]*
<expression>:'('<media_feature>[:<value>]?')'
媒体查询可以被用在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" ?>
列举几种使用方式:
@media all and (width:1024px){ body{color:#f00;} } @media all and (device-height:800px){ … } @media all and (orientation:landscape){ … } @media all and (device-aspect-ratio:16/10){ … } @media all and (min-color:1){ … } @media all and (monochrome:0){ … } @media all and (grid:0){ … }
IE | Firefox | Safari | Chrome | Opera |
---|---|---|---|---|
6.0-8.0 #1 | 4.0 | 4.0 | 4.0 | 15.0 |
9.0 |