大网数据广告活动
Web 标准与前端开发

<map>:图像映射元素

· 52CE 我爱测

HTML **`<map>`** 元素与 area 元素一起使用来定义一个图像映射(一个可点击的链接区域)。

HTML <map> 元素与 area 元素一起使用来定义一个图像映射(一个可点击的链接区域)。

HTML Demo: <map>

<map name="infographic">
  <area
    shape="poly"
    coords="130,147,200,107,254,219,130,228"
    href="https://developer.mozilla.org/docs/Web/HTML"
    alt="HTML" />
  <area
    shape="poly"
    coords="130,147,130,228,6,219,59,107"
    href="https://developer.mozilla.org/docs/Web/CSS"
    alt="CSS" />
  <area
    shape="poly"
    coords="130,147,200,107,130,4,59,107"
    href="https://developer.mozilla.org/docs/Web/JavaScript"
    alt="JavaScript" />
</map>
<img
  usemap="#infographic"
  src="/shared-assets/images/examples/mdn-info2.png"
  alt="MDN infographic" />
img {
  display: block;
  margin: 0 auto;
  width: 260px;
  height: 232px;
}

属性

这个元素包含全局属性。

  • name
    • : name 属性给予该映射引用的名称,这个属性必须存在,值不得为空并且不能带空格。name 属性的值不得与同文档中其他 <map> 元素的该属性值相同,如果还指定了 id 属性,则两个属性的值必须相同。

示例

含有两个区域的图像映射

单击左侧的鹦鹉访问 JavaScript 页面,单击右侧的鹦鹉访问 CSS 页面。

HTML


<map name="primary">
  <area
    shape="circle"
    coords="75,75,75"
    href="https://developer.mozilla.org/docs/Web/JavaScript"
    target="_blank"
    alt="JavaScript" />
  <area
    shape="circle"
    coords="275,75,75"
    href="https://developer.mozilla.org/docs/Web/CSS"
    target="_blank"
    alt="CSS" />
</map>
<img
  usemap="#primary"
  src="parrots.jpg"
  alt="两只鹦鹉的照片,大小为 350 x 150" />

结果

含有两个区域的图像映射

技术概要

<table class="properties"> <tbody> <tr> <th scope="row"><a href="/zh-CN/docs/Web/HTML/Guides/Content_categories">内容类别</a></th> <td><a href="/zh-CN/docs/Web/HTML/Guides/Content_categories#流式内容">流式内容</a>、<a href="/zh-CN/docs/Web/HTML/Guides/Content_categories#短语内容">短语内容</a>、可感知内容。</td> </tr> <tr> <th scope="row">允许的内容</th> <td>任何<a href="/zh-CN/docs/Web/HTML/Guides/Content_categories#透明内容模型">透明</a>元素。</td> </tr> <tr> <th scope="row">标签省略</th> <td>不允许,开始标签和结束标签都不能省略。</td> </tr> <tr> <th scope="row">允许的父元素</th> <td>任何接受<a href="/zh-CN/docs/Web/HTML/Guides/Content_categories#短语内容">短语内容</a>的元素。</td> </tr> <tr> <th scope="row">隐式 ARIA 角色</th> <td> <a href="https://www.w3.org/TR/html-aria/#dfn-no-corresponding-role" >没有相应的角色</a > </td> </tr> <tr> <th scope="row">允许的 ARIA 角色</th> <td>没有允许的 <code>role</code></td> </tr> <tr> <th scope="row">DOM 接口</th> <td>HTMLMapElement</td> </tr> </tbody> </table>

规范

浏览器兼容性

参见

  • a
  • area

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。