HTML 5 新增了一批用來標識常見結構的元素,讓 HTML 更具語意,使結構更清晰、更規範。問題是這些元素我們現在還不能直接大量使用——真要等瀏覽器全面支援,恐怕還得再等個十年八年。
那怎麼辦?可以借鏡微格式的思路:先用 class 名稱代替;或者隨意些,用 id 與 class 命名來表達同一份語意。重點是讓自己的結構先清晰起來,進而推廣成團隊內的規範,協作起來會順暢許多。
◎ section:可以是書中的一章或一節,泛指 HTML 4 裡任何自帶標題的區塊
◎ header:頁面的頁首;與 head 元素不同
◎ footer:頁尾;也可用於電子郵件的簽名
◎ nav:指向其他頁面的一組連結
◎ article:blog、雜誌、文章彙編中的一篇獨立內容
HTML5 的寫法:
<header>...</header>
<nav>...</nav>
<article>
<section> ... </section>
</article>
<aside>...</aside>
<footer>...</footer>
XHTML 的寫法:
<div id="header">header</div>
<div id="nav">nav</div>
<div class="article">
<div class="section">section</div>
</div>
<div id="aside">aside</div>
<div id="footer">footer</div>
HTML5:
<figure id="fig2">
<legend>Figure 2. Install Mozilla XForms dialog</legend>
<img alt="A Web site is requesting permission to install the following item: Mozilla XForms 0.7 Unsigned" src="installdialog.jpg" />
</figure>
XHTML:
<div class="figure">
<h4 class="legend">Figure 2. Install Mozilla XForms dialog</h4>
<img alt="A Web site is requesting permission to install the following item: Mozilla XForms 0.7 Unsigned" src="installdialog.jpg" />
</div>
m 元素用來標示文本中「被加上標記」的部分,但不必然帶有強調意味。你可以把它想像成書中被螢光筆畫出來的一段落。
Google 的暫存頁面就是典型用例:當你點進一份暫存副本,搜尋關鍵字便會被標記起來。例如搜尋「Egret」,暫存頁可能長這樣:
The Great <m>Egret</m> (also known as the American <m>Egret</m>) is a large white wading bird found worldwide. The Great <m>Egret</m> flies with slow wing beats. The scientific name of the Great <m>Egret</m> is Casmerodius albus.
XHTML 的對應寫法則是:
The Great <span class="m">Egret</span> (also known as the American <span class="m">Egret</span>) is a large white wading bird found worldwide...