<area> 标签定义图像映射中的可点击区域,通常与 <map> 元素一起使用。当用户单击定义了 <area> 的图像区域时,浏览器会执行预先定义的操作。
属性
alt: 定义区域的替代文本coords: 定义区域的坐标href: 定义区域链接的目标 URLshape: 定义区域的形状,可以是rect(矩形)、circle(圆形)、poly(多边形)
示例
// www.javascriptcn.com code example
<!DOCTYPE html>
<html>
<head>
<title>Image Map Example</title>
</head>
<body>
<h1>Click on the different areas of the map</h1>
<img src="example.jpg" usemap="#map1" alt="Example Image Map">
<map name="map1">
<area shape="rect" coords="0,0,50,50" href="page1.html" alt="Area 1">
<area shape="circle" coords="100,100,50" href="page2.html" alt="Area 2">
<area shape="poly" coords="200,200,250,250,200,300" href="page3.html" alt="Area 3">
</map>
</body>
</html>在上面的示例中,我们定义了一个包含三个不同形状的区域的图像地图。当用户点击不同区域时,会跳转到不同的页面。
<area> 标签在实现图像地图时非常有用,可以实现交互式的图像效果,为用户提供更好的体验。
| 属性 | 值 | 描述 |
|---|---|---|
| alt | text | 规定区域的替代文本。如果使用 href 属性,则该属性是必需的。 |
| coords | coordinates | 规定区域的坐标。 |
| href | URL | 规定区域的目标 URL。 |
| hreflang | language_code | 规定目标 URL 的语言。 |
| media | media query | 规定目标 URL 是为何种媒介/设备优化的。默认:all。 |
| nohref | value | HTML5 不支持。 规定没有相关链接的区域。 |
| rel | alternate author bookmark help license next nofollow noreferrer prefetch prev search tag | 规定当前文档与目标 URL 之间的关系。 |
| shape | default rect circle poly | 规定区域的形状。 |
| target | _blank _parent _self _top framename | 规定在何处打开目标 URL。 |
| type | MIME_type | 规定目标 URL 的 MIME 类型。注:MIME = Multipurpose Internet Mail Extensions。 |