<table>、<tr>、<td>、<th> 擁有大量屬性,現代開發多由 CSS 取代,但維護舊代碼時仍需認識。
| 屬性 | 說明 | CSS 替代 |
|---|---|---|
border | 邊框粗細 (0=無邊框) | border-width |
cellspacing | 儲存格間距 (預設 2px) | border-spacing (需 border-collapse:separate) |
cellpadding | 儲存格內邊距 (預設 1px) | padding on td, th |
width | 表格寬度 (px 或 %) | width |
height | 表格高度 | height / min-height |
align | 表格水平對齊 | margin-left/right: auto |
bgcolor | 背景顏色 | background-color |
background | 背景圖片 URL | background-image |
bordercolor | 邊框顏色 (IE 專屬) | border-color |
bordercolorlight/dark | 3D 邊框亮/暗色 (IE 專屬) | 不建議使用 |
align:水平對齊 left|center|right → text-alignvalign:垂直對齊 top|middle|bottom|baseline → vertical-alignbgcolor:背景色 → background-colorwidth/height:尺寸 → width/heightcolspan:跨欄合併 → 無 CSS 替代,屬結構屬性保留rowspan:跨列合併 → 同上nowrap:禁止換行 (td/th) → white-space: nowrap<caption>:表格標題,置於 <table> 直後。<thead>/<tbody>/<tfoot>:行群組,支援列印分頁重複表頭。<colgroup>/<col>:欄群組,設定欄寬度、樣式,配合 table-layout:fixed 極佳。新專案一律使用語意化標籤 + CSS,舊專案維護時參考對照表逐步重構。