【问题标题】:Which caption to use in a <figure> tag in HTML5?在 HTML5 的 <figure> 标签中使用哪个标题?
【发布时间】:2014-05-25 02:16:11
【问题描述】:

我读到了这个问题:Do I still need to use the title attribute if my element has a `<figcaption>`?

但答案是面向img标签,但是,如果我有以下figure,没有img,但有table

<figure title="The table of life">
  <table>
    <caption>The table of life</caption>
    <tbody>...</tbody>
  </table>
  <figcaption>The table of life<figcaption>
</figure>

这里我有 3 种方式来提供标题:&lt;caption&gt; 标签(仅适用于 table)、&lt;figcaption&gt; 标签(仅适用于 figure)和 title 属性(通用)。

哪个更好用?

这是一个没有tablefigure 示例:

<figure title="Description of my char in RPG">
  <h1>Seninha</h1>
  <p>Seninha was born in the moon in the year of 13...<p>
  <dl>
    <dt>HP</dt><dd>15</dd>
    <dt>MP</dt><dd>18</dd>
    <dt>IQ</dt><dd>99999</dd>
    <dt>ST</dt><dd>-10</dd>
  </dl>
  <figcaption>Description of my char in RPG<figcaption>
</figure>

【问题讨论】:

    标签: html semantic-markup figure


    【解决方案1】:

    caption 仅作为table 的子级有效。 The MDN docs for caption note:

    使用说明:当&lt;table&gt;元素是this的父元素时 &lt;caption&gt;&lt;figure&gt; 元素的唯一后代,使用 &lt;figcaption&gt; 元素代替。

    我会省略 title 属性,因为它没有任何贡献。

    【讨论】:

      【解决方案2】:

      HTML5 (CR) 规范 says:

      table 元素是figure 元素中除figcaption 之外的唯一内容时,应省略caption 元素以支持figcaption

      所以你应该使用figcaption,但不要使用caption

      <figure>
        <table>
          <tbody>…</tbody>
        </table>
        <figcaption>The table of life<figcaption>
      </figure>
      

      如果在table 上使用,则不应依赖title attribute,并且信息不应在title 中重复,这意味着您应该使用title figcaption 的属性而不是,如果要给出title,它不应包含与figcaption 相同的内容。

      【讨论】:

      • 那么在内容块(表格、img、段落等)中使用标题的最佳方式是 figcaption?我的意图是在我的个人网站中使用figure+figcaptiontitle 属性显示一个段落或一组段落的评论。我用了title,这是结果(葡萄牙语)seninha.net 我可以用figcaption 做到这一点,但标记会正确吗?
      • @Seninha:你为什么首先使用figure?您的示例中似乎不需要它。无论如何,使用title 属性不是为figure 提供标题的好选择,除非这个标题对于理解内容并不重要。
      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 2021-11-29
      • 1970-01-01
      • 2015-08-13
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多