HTML <a> media 屬性
實例
以下實例展示了使用media屬性的鏈接:
流覽器支持
![]()
![]()
![]()
![]()
![]()
所有主流流覽器都支持 media 屬性。
定義和用法
media 屬性規定目標 URL 是為什麼類型的媒介/設備進行優化的。
該屬性用於規定目標 URL 是為特殊設備(比如 iPhone)、語音或列印媒介設計的。
該屬性可接受多個值。
只能在 href 屬性存在時使用。
HTML 4.01 與 HTML5 之間的差異
該屬性是 HTML5 中的新屬性。
語法
可能的運算符
| 運算符 | 描述 |
|---|---|
| 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)" |

HTML <a> 標籤