HTML <area> media 屬性
實例
帶有可點擊區域的圖像映射:
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun"
href="sun.htm" media="screen and (min-color-index:256)">
</map>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun"
href="sun.htm" media="screen and (min-color-index:256)">
</map>
流覽器支持
![]()
![]()
![]()
![]()
![]()
所有主流流覽器都支持 media 屬性
定義和用法
media 屬性規定目標URL將顯示在什麼設備上。
該屬性使用與指定的URL顯示在指定的設備上 (如 iPhone) , 音頻或者列印媒介。
該attribute可以接受多個值。
僅在使用了href屬性才需要media 屬性。
HTML 4.01 與 HTML5之間的差異
The media attribute is new in HTML5.
語法
<area 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)" |
| 方向 | 指定目標顯示/紙的方向。 可能值: "portrait" 或 "landscape" 實例: media="all and (orientation: landscape)" |
| aspect-ratio | 指定的目標的顯示區域的寬度/高度比例。 通常使用 "min-" 和 "max-" 首碼。 實例: media="screen and (aspect-ratio:16/9)" |
| device-aspect-ratio | 指定的目標的顯示區域的設備寬度/設備高度比例。 通常使用 "min-" 和 "max-" 首碼。 實例: media="screen and (aspect-ratio:16/9)" |
| color | 指定目標顯示每個像素顏色的位數。 通常使用 "min-" 和 "max-" 首碼。 實例: media="screen and (color:3)" |
| color-index | Specifies the number of colors the target display can handle. 通常使用 "min-" 和 "max-" 首碼。 實例: media="screen and (min-color-index:256)" |
| monochrome | 指定在一個單色的幀緩衝器的像素位數。 通常使用 "min-" 和 "max-" 首碼。 實例: media="screen and (monochrome:2)" |
| resolution | 指定目標顯示/紙的像素密度(DPI或DPCM)。 通常使用 "min-" 和 "max-" 首碼。 實例: media="print and (resolution:300dpi)" |
| scan | 指定一個電視顯示幕的掃描方法。 可能值是 "progressive" 和 "interlace". 實例: media="tv and (scan:interlace)" |
| grid | 指定輸出設備是電網或位圖 grid的值為 "1", 其他的為 "0" 實例: media="handheld and (grid:1)" |

HTML <area> 標籤