最小化細線邊框表格
<style>
.table {
border-collapse: collapse; /* 關鍵:合併相鄰邊框為 1px */
width: 100%;
}
.table th, .table td {
border: 1px solid #e0e0e0; /* 統一細線 */
padding: 10px 12px;
}
</style>
<table class="table">
<thead><tr><th>名稱</th><th>價格</th></tr></thead>
<tbody>
<tr><td>商品 A</td><td>$100</td></tr>
<tr><td>商品 B</td><td>$200</td></tr>
</tbody>
</table>
設計系統色彩變數(CSS Custom Properties)
:root {
--table-border-color: #dee2e6;
--table-border-width: 1px;
--table-header-bg: #f8f9fa;
--table-row-hover: #eef5ff;
--table-striped: #fdfdfd;
}
.table {
border-collapse: collapse;
border: var(--table-border-width) solid var(--table-border-color);
}
.table th, .table td {
border: var(--table-border-width) solid var(--table-border-color);
padding: 0.75rem 1rem;
}
.table thead th { background: var(--table-header-bg); }
.table tbody tr:nth-child(even) { background: var(--table-striped); }
.table tbody tr:hover { background: var(--table-row-hover); }
無障礙對比度合規
| 邊框色 | 對白底對比度 | WCAG 1.4.11 (3:1) | 建議 |
#dee2e6 | 1.6:1 | ❌ 不通過 | 避免用於邊框 |
#adb5bd | 3.1:1 | ✅ 通過 | 最小可用 |
#868e96 | 4.5:1 | ✅ AA 級 | 推薦標準 |
#495057 | 7.0:1 | ✅ AAA 級 | 高對比度模式 |
常見版型變體
<!-- 1. 僅外框 -->
.table-outer { border: 2px solid #333; }
.table-outer th, .table-outer td { border: none; border-bottom: 1px solid #eee; }
.table-outer tr:last-child td { border-bottom: none; }
<!-- 2. 僅橫向分隔線 -->
.table-horizontal th, .table-horizontal td { border: none; border-bottom: 1px solid #eee; }
.table-horizontal thead th { border-bottom-width: 2px; }
<!-- 3. 斑馬紋無邊框 -->
.table-zebra { border-collapse: collapse; }
.table-zebra td { border: none; padding: 12px; }
.table-zebra tbody tr:nth-child(odd) { background: #f8f9fa; }