表格 <table>
以二維資料表來呈現資訊,適合數據類的網站使用。
表格標籤的功能
<table>、<tr>、<th>、<td> 為表格中常見到的四個標籤。
<table>: 包覆表格內容。<tr>: 表格的列數。<th>: 表格的欄位、欄位標題。(預設:粗體字、文字置中)<td>: 表格的欄位。
非必要使用
<caption>、<thead>、<tbody>、<tfoot>、<th>。
<caption>: 表格的標題。<thead>: 表格的首列。<tbody>: 表格的內容。<tfoot>: 表格的尾列。
html
<table>
<caption>購物清單</caption>
<thead>
<tr>
<th>商品名稱</th>
<th>數量</th>
<th>價格</th>
</tr>
</thead>
<tbody>
<tr>
<td>iPhone 20 Pro Max</td>
<td>1</td>
<td>43,000</td>
</tr>
<tr>
<td>iPad mini</td>
<td>1</td>
<td>16,900</td>
</tr>
<tr>
<td>Mac mini M20 Pro</td>
<td>1</td>
<td>46,900</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="2">合計</th>
<td>106,800</td>
</tr>
</tfoot>
</table>| 商品名稱 | 數量 | 價格 |
|---|---|---|
| iPhone 20 Pro Max | 1 | 43,000 |
| iPad mini | 1 | 16,900 |
| Mac mini M20 Pro | 1 | 46,900 |
| 合計 | 106,800 | |
colspan
在該列中,設定合併欄位數量。
rowspan
在該欄中,設定合併列位數量。
