2014-05-25 179 views
2

我读了这个问题:Do I still need to use the title attribute if my element has a `<figcaption>`?HTML5中的<figure>标签中使用哪个标题?

但是我的回答是面向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个给出标题的方法有:<caption>标记(仅用于table),<figcaption>标记(仅用于figure)和title属性(通用)。

哪一个更好用?

这里是figure一个例子,而不table

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

回答

3

caption只是作为table孩子有效。 The MDN docs for caption note

用法注:当<table>元素是这个 <caption>父是<figure>元素的唯一传人,使用 <figcaption>元素来代替。

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

1

的HTML5(CR)符合规范says

table元件处于比figcaption以外的figure元件的唯一内容时,caption元件应该有利于figcaption的被省略。

所以,你应该用figcaption但没有caption

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

如果table使用你不应该依靠title attribute和信息不应该在title被复制,这样就意味着你应该不是使用title属性而不是figcaption,如果你wan t给出title,它不应该包含与figcaption相同的内容。

+0

因此,在一块内容(表格,img,段落等)中使用标题的最佳方式是figcaption? 我的意图是在我的个人网站上使用“figure + figcaption”或“title”属性显示段落或一组段落的评论。我用'title'这里是结果(在葡萄牙语中)http://seninha.net 我可以用'figcaption'来做,但标记会正确吗? – Seninha

+0

@Seninha:你为什么首先使用'figure'?看起来你的例子中不需要它。无论如何,使用'title'属性不是提供'figure'标题的好选择,除非这个标题对于理解内容并不重要。 – unor