我读到这个问题:如果我的元素有`<图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
中重复,因此这意味着您不应使用figcaption
的title
属性,而应,并且如果您要提供title
,则它不应包含与figcaption
相同的内容。