<table> 專為**表格化資料**設計(財報、課表、產品規格對比),**嚴禁用於版面佈局**。現代佈局請使用 CSS Flexbox/Grid。本文教學針對資料表格的建立、編輯、無障礙與響應式優化。
100%(響應式)或固定像素。1(或 0 由 CSS 控制)。0(由 CSS 控制)。






<table>
<caption>2024 年產品銷售統計</caption>
<thead>
<tr>
<th scope="col">產品</th>
<th scope="col">Q1</th>
<th scope="col">Q2</th>
<th scope="col">Q3</th>
<th scope="col">Q4</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">產品 A</th>
<td>1,200</td>
<td>1,350</td>
<td>1,100</td>
<td>1,500</td>
</tr>
<!-- 更多資料列 -->
</tbody>
<tfoot>
<tr>
<th scope="row">總計</th>
<td>5,150</td>
<td>...</td>
</tr>
</tfoot>
</table>
<caption>:表格標題(取代舊版 summary 屬性,HTML5 標準)。<thead>, <tbody>, <tfoot>:語意分組,支援 CSS 針對性樣式、列印分頁控制。<th scope="col/row">:明確標示標題儲存格範疇,螢幕閱讀器正確關聯。| 操作 | 設計視圖 | 代碼視圖 |
|---|---|---|
| 調整整體寬度 | 拖曳表格右邊框 | 修改 <table style="width: 100%"> 或 CSS |
| 調整欄寬 | 拖曳儲存格分隔線 | 在 <col> 或 <th> 設定 width |
| 調整列高 | 拖曳水平分隔線 | 設定 <tr style="height: 40px"> |
| 合併儲存格 | 選取多格 → 右鍵 → 合併儲存格 | 加入 colspan="2" / rowspan="3" |
| 拆分儲存格 | 右鍵 → 拆分儲存格 → 輸入行/列數 | 移除 colspan/rowspan 或調整結構 |
| 新增/刪除列/欄 | 右鍵列/欄標題 → 插入/刪除 | 複製/刪除 <tr> / <th><td> |



<style>
/* 表格基礎重設 */
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { border: 1px solid #ddd; padding: 0.75rem; text-align: left; }
th { background: #f5f5f5; font-weight: 600; white-space: nowrap; }
tbody tr:nth-child(even) { background: #fafafa; } /* 斑馬紋 */
tbody tr:hover { background: #eef; } /* 懸停高亮 */
caption { caption-side: top; padding: 1rem; font-weight: bold; font-size: 1.1rem; }
/* 響應式:小螢幕橫向捲動 */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
</style>
<div class="table-wrapper">
<table>...</table>
</div>
$('#myTable').DataTable(); 初始化。<caption> 描述表格主旨。<th> 使用 scope="col|row"。summary 屬性(HTML5 雖棄用但螢幕閱讀器仍支援)。Dreamweaver 提供直觀的表格視覺化編輯體驗,但專業開發者必須掌握語意化標籤(thead/tbody/tfoot, th scope, caption)、CSS 分離樣式、響應式包裝器、無障礙屬性。拒絕「版面佈局用表格」,讓表格回歸資料呈現本質,打造結構清晰、無障礙友善、易於維護的資料表格。