早期 HTML 透過 bordercolorlight 與 bordercolordark 模擬立體感,配合 border、cellspacing 等屬性:
<table border="1" cellspacing="0" width="100%"
bordercolorlight="#333333" bordercolordark="#efefef">
<tr bgcolor="#cccccc">
<td>cnbruce</td><td>cnbruce</td><td>cnbruce</td><td>cnbruce</td>
</tr>
<tr bgcolor="#cccccc">
<td>cnbruce</td><td>cnbruce</td><td>cnbruce</td><td>cnbruce</td>
</tr>
</table>
缺點明顯: 僅支援單色邊框、無法控制陰影漸層、不支援圓角、語意與表現耦合、RWD 極難處理,**已被 HTML5 棄用**,僅供維護舊專案參考。
border-style: outset/inset(最簡單,效果有限).table-3d-simple {
border-collapse: separate;
border-spacing: 0;
border: 4px outset #ccc; /* 整體外凸 */
}
.table-3d-simple td {
border: 2px inset #fff; /* 儲存格內凹 */
background: #f9f9f9;
}
瀏覽器自動根據邊框色計算高光/陰影,但色彩控制力弱,且 border-collapse: separate 會產生雙線縫隙。
利用 linear-gradient 模擬光源方向,配合 box-shadow 強化立體感:
.table-3d-modern {
border-collapse: collapse;
width: 100%;
max-width: 800px;
margin: 2rem auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
box-shadow:
0 4px 12px rgba(0,0,0,0.08),
0 0 0 1px rgba(0,0,0,0.05); /* 外層微邊框 */
border-radius: 8px; /* 整體圓角 */
overflow: hidden; /* 裁切內部圓角 */
}
.table-3d-modern th,
.table-3d-modern td {
padding: 14px 20px;
text-align: left;
border-bottom: 1px solid #e8eef4;
}
/* 表頭:深色背景 + 頂部高光邊框 */
.table-3d-modern thead th {
background: linear-gradient(180deg, #2c3e50 0%, #1a252f 100%);
color: #fff;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
border-bottom: 2px solid #3a506b; /* 分隔線 */
/* 頂部高光模擬 */
background-clip: padding-box;
position: relative;
}
.table-3d-modern thead th::before {
content: "";
position: absolute;
top: 0; left: 0; right: 0;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
}
/* 儲存格:細微內凹感 */
.table-3d-modern tbody td {
background: #fff;
background-image: linear-gradient(180deg, #fdfdfd 0%, #f5f7fa 100%);
transition: background 0.2s ease;
}
.table-3d-modern tbody tr:last-child td {
border-bottom: none;
}
.table-3d-modern tbody tr:hover td {
background: #eef5ff;
background-image: linear-gradient(180deg, #eef5ff 0%, #dfeaff 100%);
}
/* 列首欄加強 */
.table-3d-modern tbody th {
background: #f8f9fa;
font-weight: 500;
color: #333;
border-right: 1px solid #e8eef4;
}
近年流行的柔和立體風格,適合深色模式:
.table-neumorphism {
border-collapse: separate;
border-spacing: 8px; /* 必須分離邊框才能做陰影 */
background: #e0e5ec;
border-radius: 16px;
padding: 16px; /* 容器內距 */
box-shadow:
8px 8px 16px #bec5cd,
-8px -8px 16px #ffffff;
}
.table-neumorphism th,
.table-neumorphism td {
padding: 12px 18px;
border-radius: 8px;
background: #e0e5ec;
box-shadow: inset 4px 4px 8px #bec5cd, inset -4px -4px 8px #ffffff;
border: none;
}
.table-neumorphism thead th {
box-shadow: inset -4px -4px 8px #bec5cd, inset 4px 4px 8px #ffffff; /* 反向凸起 */
color: #555;
font-weight: 600;
}
注意: border-collapse: separate 與 border-spacing 會破壞表格對齊精度,複雜表格慎用。
| 場景 | 推薦方案 | 關鍵技術 |
|---|---|---|
| 一般資料表格 | 方案二(漸層+陰影) | linear-gradient, box-shadow, border-collapse: collapse |
| 儀表板/卡片式表格 | 方案三 | border-collapse: separate, inset box-shadow |
| 舊專案維護 | 方案一或保留屬性 | bordercolorlight/dark(不建議新專案使用) |
border-radius 於 border-collapse: collapse 表格僅對最外層生效,內部圓角需改用 separate 或偽元素模擬。現代 CSS 賦予我們對光影的精細掌控,拋棄僵化的屬性式立體邊框,擁抱漸層、陰影與動畫,打造既美觀又符合工程規範的資料呈現體驗。