
- HTML中文网
- 联系QQ:88526
  
- QQ交流群
 
- 微信公众号
 

CSS媒体查询
<media_query_list>:[<media_query>[',' <media_query>]*]?
<media_query>:[only | not]? <media_type> [and <expression>]* | <expression> [and <expression>]*
<expression>:'('<media_feature>[:<value>]?')'
通过不同的媒体类型和条件定义样式表规则。
媒体查询让CSS可以更精确作用于不同的媒体类型和同一媒体的不同条件。
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 | 
推荐手册