2014-05-25 56 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