為了在原始碼中清楚區分表格結構,HTML 規定了 <thead>、<tbody>、<tfoot> 三個標記,分別對應表格的表首、主體與表尾。<thead> 用於定義表格最上端表首的樣式。
<thead align=value1 bgcolor=color_value valign=value2>
align 代表水平對齊:Left 靠左、Center 居中、Right 靠右。valign 代表垂直對齊:Top 靠上、Middle 居中、Bottom 靠下。
透過標記設定表格表首樣式。
01 <!-- ------------------------------ -->
02 <!-- 檔案範例:10-44.htm -->
03 <!-- 檔案說明:設定表格表首樣式 -->
04 <!-- ------------------------------ -->
05 <html>
06 <head>
07 <title>設定表格表首樣式</title>
08 </head>
09 <body>
10 <table border=3 width=400 height=100 bordercolor=#336699 align="Center">
11 <thead align=center bgcolor=#00ccff>
12 <tr>
13 <td colspan=2>網頁製作軟體</td>
14 </tr>
15 </thead>
16 <tr>
17 <td>網頁圖像軟體</td><td>Fireworks</td>
18 </tr>
19 <tr>
20 <td>網頁製作軟體</td><td>Dreamweaver</td>
21 </tr>
22 <tr>
23 <td>網頁動畫軟體</td><td>Flash</td>
24 </tr>
25 </table>
26 </body>
27 </html>
第 11 行定義了表首樣式,第 15 行以 </thead> 收尾。第 13 行用 colspan=2 讓標題橫跨兩欄,這是表首常見的寫法。
結構上的好處:thead/tbody/tfoot 讓表格在語意上分成三塊,除了便於統一套用樣式,也能讓長表格在列印時於每頁重複輸出表頭。