HTML 5 <a> 标签的 media 属性
实例
带有 media 属性的链接:
<a href="att_a_media.asp?output=print" media="print and (resolution:300dpi)">
HTML5 a media attribute.
</a>
定义和用法
media 属性规定目标 URL 是为什么类型的媒介/设备进行优化的。
该属性用于规定目标 URL 是为特殊设备(比如 iPhone)、语音或打印媒介设计的。
该属性可接受多个值。
只能在 href 属性存在时使用。
HTML 4.01 与 HTML 5 之间的差异
该属性是 HTML5 中的新属性。
语法
<a media="value">
可能的运算符
| 运算符 | 描述 |
|---|---|
| and | 规定 AND 运算符。 |
| not | 规定 NOT 运算符。 |
| , | 规定 OR 运算符。 |
设备
| 值 | 描述 |
|---|---|
| all | 默认。适合所有设备。 |
| aural | 语音合成器。 |
| braille | 盲文反馈装置。 |
| handheld | 手持设备(小屏幕、有限的带宽)。 |
| projection | 投影机。 |
| 打印预览模式/打印页面。 | |
| screen | 计算机屏幕。 |
| tty | 电传打字机以及使用等宽字符网格的类似媒介。 |
| tv | 电视类型设备(低分辨率、有限的分页能力)。 |
值
| 值 | 描述 |
|---|---|
| width |
规定目标显示区域的宽度。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (min-width:500px)" |
| height |
规定目标显示区域的高度。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (max-height:700px)" |
| device-width |
规定目标显示器/纸张的宽度。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (device-width:500px)" |
| device-height |
规定目标显示器/纸张的高度。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (device-height:500px)" |
| orientation |
规定目标显示器/纸张的取向。 可能的值:"portrait" 或 "landscape" 例子:media="all and (orientation: landscape)" |
| aspect-ratio |
规定目标显示区域的宽度/高度比。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (aspect-ratio:16/9)" |
| device-aspect-ratio |
规定目标显示器/纸张的 device-width/device-height 比率。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (aspect-ratio:16/9)" |
| color |
规定目标显示器的 bits per color。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (color:3)" |
| color-index |
规定目标显示器能够处理的颜色数。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (min-color-index:256)" |
| monochrome |
规定在单色帧缓冲中的每像素比特。 可使用 "min-" 和 "max-" 前缀。 例子:media="screen and (monochrome:2)" |
| resolution |
规定目标显示器/纸张的像素密度 (dpi or dpcm)。 可使用 "min-" 和 "max-" 前缀。 例子:media="print and (resolution:300dpi)" |
| scan |
规定 tv 显示器的扫描方法。 可能的值是:"progressive" 和 "interlace"。 例子:media="tv and (scan:interlace)" |
| grid |
规定输出设备是网格还是位图。 可能的值:"1" 代表网格,"0" 是其他。 例子:media="handheld and (grid:1)" |