<table>
<tr>
<td>儲存格 1-1</td>
<td>儲存格 1-2</td>
</tr>
<tr>
<td>儲存格 2-1</td>
<td>儲存格 2-2</td>
</tr>
</table>
<table>:表格容器。<tr> (Table Row):表格列。<td> (Table Data):資料儲存格。| 屬性 | 標籤 | 說明 | 現代 CSS 替代 |
|---|---|---|---|
border | <table> | 邊框粗細 (像素) | table { border: 1px solid #ccc; border-collapse: collapse; } |
width | <table>, <td>, <th> | 寬度 (px/% ) | width, max-width, <col style="width:..."> |
height | <table>, <td>, <th> | 高度 | height, min-height |
cellpadding | <table> | 儲存格內邊距 | td, th { padding: 8px; } |
cellspacing | <table> | 儲存格間距 | table { border-collapse: collapse; } (合併邊框) 或 border-spacing: 10px; (分離邊框) |
bgcolor | <table>, <tr>, <td>, <th> | 背景顏色 | background-color: #f5f5f5; |
align | <table> | 表格水平對齊 | table { margin: 0 auto; } (置中) |
align | <tr>, <td>, <th> | 儲存格文字水平對齊 | text-align: center/left/right; |
valign | <tr>, <td>, <th> | 儲存格文字垂直對齊 | vertical-align: top/middle/bottom; |
bordercolor | <table> | 邊框顏色 | border-color: #ccc; |
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<title>簡易表格範本</title>
<style>
.simple-table {
border-collapse: collapse;
width: 100%;
max-width: 600px;
margin: 2rem auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.simple-table th, .simple-table td {
border: 1px solid #ddd;
padding: 10px 12px;
text-align: left;
}
.simple-table thead th {
background: #f0f4f8;
font-weight: 600;
}
.simple-table tbody tr:nth-child(odd) {
background: #fafafa;
}
.simple-table .center { text-align: center; }
.simple-table .right { text-align: right; }
</style>
</head>
<body>
<table class="simple-table">
<caption>員工基本資料表</caption>
<colgroup>
<col style="width: 60px;"> <!-- 工號 -->
<col style="width: 30%;"> <!-- 姓名 -->
<col style="width: 120px;"> <!-- 部門 -->
<col> <!-- 備註 -->
</colgroup>
<thead>
<tr>
<th>工號</th>
<th>姓名</th>
<th class="center">部門</th>
<th>備註</th>
</tr>
</thead>
<tbody>
<tr>
<td class="center">A001</td>
<td>陳志明</td>
<td class="center">研發部</td>
<td>資深工程師</td>
</tr>
<tr>
<td class="center">A002</td>
<td>林靜宜</td>
<td class="center">行銷部</td>
<td>專案經理</td>
</tr>
<tr>
<td class="center">A003</td>
<td>王大偉</td>
<td class="center">業務部</td>
<td>區域經理</td>
</tr>
</tbody>
</table>
</body>
</html>
<table class="layout-table" style="width: 100%; border-collapse: collapse;">
<tr>
<td rowspan="2" style="width: 200px; background: #e8f5e9; vertical-align: top; padding: 1rem;">
<strong>側邊欄內容</strong><br>
選單 1<br>選單 2<br>選單 3
</td>
<td style="padding: 1rem; background: #fff;">
<h2>主要內容區塊</h2>
<p>這裡放主要文章內容...</p>
</td>
</tr>
<tr>
<td style="padding: 1rem; background: #fafafa;">
<h3>次要內容區塊</h3>
<p>底部補充資訊...</p>
</td>
</tr>
</table>
⚠️ 注意:現代網頁版面**強烈建議使用 CSS Flexbox/Grid 取代表格佈局**。表格佈局僅適用於**表格化資料** 或 **HTML Email** (郵件客戶端相容性)。
table>thead>tr>th*4^^tbody>tr*5>td*4 按 Tab 產生 4 欄 5 列含表頭表格。table.simple>tr*3>td{Cell $}*4 產生帶類別、自動編號內容的表格。<caption> 說明表格用途。<th> 而非 <td>。<th> 加上 scope="col" 或 scope="row"。headers + id 關聯。HTML 表格語法簡單,但要寫出**語意正確、無障礙、響應式、易維護**的表格,需掌握 <thead>/<tbody> 結構、<colgroup> 定寬、CSS border-collapse/table-layout、語意屬性 scope/headers。從簡易範本開始,漸進套用最佳實踐,打造專業級資料呈現。