<table border="1">
<tr>
<td>儲存格 1</td>
<td>儲存格 2</td>
</tr>
<tr>
<td>儲存格 3</td>
<td>儲存格 4</td>
</tr>
</table>
<table width="600" border="1" bordercolor="green" cellspacing="0" cellpadding="10" bgcolor="#ffffcc">
<tr>
<td width="150" height="50">欄位 A</td>
<td>欄位 B</td>
<td>欄位 C</td>
<td>欄位 D</td>
</tr>
<tr>
<td height="50">資料 1</td>
<td>資料 2</td>
<td>資料 3</td>
<td>資料 4</td>
</tr>
<tr>
<td height="50">資料 5</td>
<td>資料 6</td>
<td>資料 7</td>
<td>資料 8</td>
</tr>
<tr>
<td height="50">資料 9</td>
<td>資料 10</td>
<td>資料 11</td>
<td>資料 12</td>
</tr>
</table>
| 屬性 | 作用 | 建議值/備註 |
|---|---|---|
| width | 表格寬度 | 像素或百分比(如 100%) |
| border | 外框粗細 | 數字(像素),0 為無框線 |
| bordercolor | 外框顏色 | 十六進位或顏色名稱 |
| cellspacing | 儲存格間距 | 0 可讓邊框合併為單線 |
| cellpadding | 內容與框線距離 | 建議 8~12px 提升可讀性 |
| bgcolor | 整表背景色 | 已棄用,請用 CSS background-color |
| align (table) | 表格水平對齊 | left/center/right,建議用 CSS margin |
<style>
.modern-table {
width: 100%;
border-collapse: collapse; /* 合併邊框,等同 cellspacing=0 */
font-family: system-ui, sans-serif;
}
.modern-table th,
.modern-table td {
border: 1px solid #e0e0e0;
padding: 12px 16px;
text-align: left;
}
.modern-table th {
background: #f5f5f5;
font-weight: 600;
}
.modern-table tbody tr:nth-child(even) {
background: #fafafa; /* 斑馬紋 */
}
.modern-table tbody tr:hover {
background: #eef; /* 滑鼠懸停高亮 */
}
</style>
<table class="modern-table">
<thead>
<tr><th>名稱</th><th>價格</th><th>狀態</th></tr>
</thead>
<tbody>
<tr><td>商品 A</td><td>$1,200</td><td>現貨</td></tr>
<tr><td>商品 B</td><td>$890</td><td>缺貨</td></tr>
</tbody>
</table>
<td></td> 或加 CSS min-width<th scope="col"> 告訴螢幕閱讀器這是欄標題<div class="table-responsive">
<table class="modern-table">...</table>
</div>
<style>
.table-responsive {
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
</style>
在小螢幕時自動出現水平捲軸,不破壞版面。