有些標籤明明很實用,卻很少在一般網站上出現,於是每次遇到都覺得新鮮。以下五個算是筆記性質的整理,多數屬於 HTML5 新增,使用時仍要留意瀏覽器支援情況。
<table border="2" contenteditable="true">
<caption>Monthly savings</caption>
<tr><th>Month</th><th>Savings</th></tr>
<tr><td>January</td><td><div contenteditable="true">$100</div></td></tr>
<tr><td>February</td><td><div contenteditable="true">$50</div></td></tr>
</table>
加上這個屬性後,表格內容可以直接改,完全不需要另外放輸入框。子元素若沒有指定,會繼承父層設定,所以很方便(也因此,如果加在 body 上,整頁都會變成可編輯狀態)。
相當於桌面開發裡的 GroupBox,用 legend 指定標題:
<fieldset>
<legend>Index:</legend>
<ul>
<li><a href="#">Index of all articles</a></li>
<li><a href="#">Things to wake up for today</a></li>
</ul>
</fieldset>
搭配 map 與 img 的 usemap 屬性,可以替圖片的特定形狀加上連結:
<img src="planets.gif" usemap="#planetmap" width="145" height="126" alt="Planets">
<map name="planetmap">
<area alt="Sun" coords="0,0,82,126" shape="rect" href="sun.htm">
<area alt="Mercury" coords="90,58,3" shape="circle" href="mercur.htm">
</map>
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">
0 <input type="range" id="a" value="50"> 100
+ <input type="number" id="b" value="50">
= <output name="x" for="a b"></output>
</form>
拖动滑桿就能看到加總即時更新,語意上比隨便用個 span 合適得多。
<p>Do not forget to buy <mark>milk</mark> today.</p>
不需要把文字拆開、也不需要用 background-color 硬湊,mark 天生就是「標記重點」的意思。