表格用於呈現結構化資料。本文說明 <table> 核心結構、常用屬性與實際範例。
<table>
<caption>表格標題</caption>
<thead>
<tr>
<th>表頭 1</th>
<th>表頭 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>資料 1-1</td>
<td>資料 1-2</td>
</tr>
<tr>
<td>資料 2-1</td>
<td>資料 2-2</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>合計</td>
<td>100</td>
</tr>
</tfoot>
</table>
<table>:表格容器<caption>:表格標題(語意化、無障礙)<thead>、<tbody>、<tfoot>:行群組,利於樣式與列印控制<tr>:表格列<th>:表頭儲存格(預設粗體置中)<td>:資料儲存格border:邊框寬度(已棄用,改用 CSS border)cellpadding:儲存格內邊距(改用 CSS padding)cellspacing:儲存格間距(改用 CSS border-collapse: collapse;)width:表格寬度(改用 CSS)colspan="n":橫向合併 n 格rowspan="n":縱向合併 n 格<th> 標記表頭,並加上 scope="col|row"<caption> 或 aria-describedby 說明表格用途| 姓名 | 數學 | 英文 |
|---|---|---|
| 小明 | 90 | 85 |
| 小華 | 78 | 92 |