HTML 表格提供了不少屬性來精細控制框線的顯示與隱藏。掌握這些屬性,就能輕鬆做出各種表格樣式,以下做個系統性整理。
表格的基礎屬性包含:width(寬度)、height(高度)、border(邊框值)、cellspacing(儲存格之間的間隔)、cellpadding(儲存格內容與邊框的間隔)、bordercolorlight(亮邊框顏色)、bordercolordark(暗邊框顏色)、bgcolor(背景色)、background(背景圖片)與 bordercolor(邊框顏色)。
控制表格內部分隔線的是 rules 參數,它有三個值:
rules=cols:隱藏橫向分隔線,只看得到「列」。rules=rows:隱藏縱向分隔線,只看得到「行」。rules=none:縱橫分隔線全部隱藏,只剩表格外框。表格外框的顯示與隱藏則由 frame 參數控制,注意它只對外框起作用,不影響內部線條:
<table frame=above><table frame=below><table frame=vsides><table frame=hsides><table frame=lhs><table frame=rhs><table frame=void>以下是一個運用 thead、tbody、tfoot 與 scope 的語義化表格:
<table summary="學生名單,包括學生編號、姓名、聯繫電話和地址。">
<caption>學生名單</caption>
<thead>
<th scope="col">編號</th>
<th scope="col">姓名</th>
<th scope="col">聯繫電話</th>
<th scope="col">地址</th>
</thead>
<tfoot>
<td colspan="4">班主任:</td>
</tfoot>
<tbody>
<tr>
<td>1</td><td>Jamson</td>
<td>123-45678</td><td>XX市XX區XX號</td>
</tr>
</tbody>
</table>