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

<figure>:可附标题内容元素

· 52CE 我爱测

HTML **`<figure>`** 元素代表一段独立的内容,可能包含 figcaption 元素定义的说明元素。该插图、标题和其中的内容通常作为一个独立的引用单元。

HTML <figure> 元素代表一段独立的内容,可能包含 figcaption 元素定义的说明元素。该插图、标题和其中的内容通常作为一个独立的引用单元。

HTML Demo: <figure>

<figure>
  <img
    src="/shared-assets/images/examples/elephant.jpg"
    alt="Elephant at sunset" />
  <figcaption>An elephant at sunset</figcaption>
</figure>
figure {
  border: thin #c0c0c0 solid;
  display: flex;
  flex-flow: column;
  padding: 5px;
  max-width: 220px;
  margin: auto;
}

img {
  max-width: 220px;
  max-height: 150px;
}

figcaption {
  background-color: #222;
  color: #fff;
  font: italic smaller sans-serif;
  padding: 3px;
  text-align: center;
}

<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> figcaption 元素,且紧随着<a href="/zh-CN/docs/Web/HTML/Guides/Content_categories#流式内容">流式内容</a>;或紧随流式内容的 figcaption 元素;或流式内容。 </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="/zh-CN/docs/Web/Accessibility/ARIA/Roles/Figure_Role" >figure</a > </td> </tr> <tr> <th scope="row">允许的 ARIA 角色</th> <td> 无子 <a href="/zh-CN/docs/Web/HTML/Reference/Elements/figcaption">figcaption</a> 元素:<a href="https://www.w3.org/TR/html-aria/#dfn-any-role">any</a>,否则没有允许的角色 </td> </tr> <tr> <th scope="row">DOM 接口</th> <td>HTMLElement</td> </tr> </tbody> </table>

属性

此元素只包含全局属性。

使用说明

  • 通常,<figure> 的内容为图像、插图、图表、代码片段等,在文档的主内容流中引用,但可以移动到文档的另一部分或附录而不影响主内容流。
  • 通过在其中插入 figcaption(作为第一个或最后一个子元素),可以将标题与 <figure> 元素相关联。图中找到的第一个 <figcaption> 元素显示为图的标题。

示例

图像


<figure>
  <img
    src="/zh-CN/docs/Web/HTML/Element/figure/favicon-192x192.png"
    alt="The beautiful MDN logo." />
</figure>


<figure>
  <img
    src="/zh-CN/docs/Web/HTML/Element/figure/favicon-192x192.png"
    alt="The beautiful MDN logo." />
  <figcaption>MDN Logo</figcaption>
</figure>

图像

代码段

<figure>
  <figcaption>使用 <code>navigator</code> 获取浏览器的信息。</figcaption>
  <pre>
function NavigatorExample() {
  var txt;
  txt = "Browser CodeName: " + navigator.appCodeName + "; ";
  txt+= "Browser Name: " + navigator.appName + "; ";
  txt+= "Browser Version: " + navigator.appVersion  + "; ";
  txt+= "Cookies Enabled: " + navigator.cookieEnabled  + "; ";
  txt+= "Platform: " + navigator.platform  + "; ";
  txt+= "User-agent header: " + navigator.userAgent  + "; ";
  console.log("NavigatorExample", txt);
}
  </pre>
</figure>

代码段

引用

<figure>
  <figcaption><b>Edsger Dijkstra:</b></figcaption>
  <blockquote>
    If debugging is the process of removing software bugs, then programming must
    be the process of putting them in.
  </blockquote>
</figure>

引用

诗歌

<figure>
  <p style="white-space:pre">
    Bid me discourse, I will enchant thine ear, Or like a fairy trip upon the
    green, Or, like a nymph, with long dishevelled hair, Dance on the sands, and
    yet no footing seen: Love is a spirit all compact of fire, Not gross to
    sink, but light, and will aspire.
  </p>
  <figcaption><cite>Venus and Adonis</cite>, by William Shakespeare</figcaption>
</figure>

诗歌

规范

浏览器兼容性

参见

  • figcaption 元素

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

资料来源与适用范围

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

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

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