<map> 與 <area> 圖像熱區完整教學單一圖片上定義多個可點擊熱區,每個熱區連結不同網址或錨點。典型應用:地圖選擇、產品圖標註、儀表板互動。
<img src="solar.jpg" usemap="#solarmap" alt="太陽系">
<map name="solarmap">
<area shape="circle" coords="100,100,30" href="sun.html" alt="太陽">
<area shape="circle" coords="200,100,20" href="mercury.html" alt="水星">
<area shape="poly" coords="300,80, 320,120, 280,120" href="venus.html" alt="金星">
</map>
<area> 形狀與座標| shape | coords 格式 | 說明 |
|---|---|---|
| rect | x1,y1,x2,y2 | 矩形,左上/右下座標 |
| circle | x,y,r | 圓形,中心點與半徑 |
| poly | x1,y1,x2,y2,...,xn,yn | 多邊形,依序頂點座標 |
| default | 無 | 整張圖片其餘區域 |
$0 選取 <img>,滑鼠移動觀察 offsetX/offsetY。<area> 必須有有意義的 alt 屬性。SVG <a> 包裹 <path>/<circle> 可實現向量級熱區,支援 CSS 動畫、媒體查詢、任意解析度不失真,為現代專案首選。