<figure> 在 HTML5 中的标签中使用哪个标题?



我读到这个问题:如果我的元素有`<图caption>`?

但是答案指向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>

这里我有三种方式来给出标题:<caption>标签(仅适用于table(、<figcaption>标签(仅用于figure(和title属性(泛型(。

哪一个更好用?

以下是没有table:的figure的示例

<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>

caption仅作为table的子级有效。caption的MDN文档注释:

用法说明:当作为此的父级的<table>元素<caption><figure>元素的唯一后代,请使用CCD_ 18元素。

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

HTML5(CR(规范说:

table元素是除figcaption之外的figure元素中的唯一内容时,为了有利于figcaption,应该省略caption元素。

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

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

如果在table上使用title属性,则不应依赖该属性,并且信息永远不应在title中重复,因此这意味着您不应使用figcaptiontitle属性,而应,并且如果您要提供title,则它不应包含与figcaption相同的内容。

最新更新