早期 HTML 提供 bordercolorlight、bordercolordark 兩屬性,配合 border>=1 產生 3D 凸起/凹陷邊框。這兩屬性已被 HTML5 棄用,現代改用 CSS border-top/left、border-bottom/right 或 box-shadow 實現更豐富的立體效果。本文詳細對照舊屬性與現代寫法。
| 屬性 | 作用邊框 | 視覺效果 | 生效條件 |
|---|---|---|---|
| bordercolorlight | 上、左 | 亮面(光源左上) | border>=1 |
| bordercolordark | 下、右 | 暗面(陰影面) | border>=1 |
<TABLE BORDER=3 WIDTH=400 HEIGHT=100 BORDERCOLORLIGHT=#336699>
<TR><TD>網頁圖像軟體</TD><TD>Fireworks</TD></TR>
<TR><TD>網頁製作軟體</TD><TD>Dreamweaver</TD></TR>
</TABLE>
結果:整張表格呈現藍色系 3D 凸起邊框(左上亮、右下暗)。
.table-3d {
border-collapse: collapse;
}
.table-3d td, .table-3d th {
border-width: 3px;
border-style: solid;
border-top-color: #336699; /* 亮面 */
border-left-color: #336699; /* 亮面 */
border-bottom-color: #003366; /* 暗面 */
border-right-color: #003366; /* 暗面 */
padding: 8px;
}
優點:可獨立控制四邊顏色、寬度、樣式(solid/double/ridge/inset/outset)。
.inset { border: 3px inset #336699; } /* 凹陷 */
.outset { border: 3px outset #336699; } /* 凸起 */
.ridge { border: 3px ridge #336699; } /* 山脊 */
.groove { border: 3px groove #336699; } /* 溝槽 */
瀏覽器自動計算亮/暗面,**零配色負擔**,但顏色細節不可控。
.table-modern {
border-collapse: collapse;
box-shadow:
2px 2px 4px rgba(0,0,0,0.15), /* 右下陰影 */
-2px -2px 4px rgba(255,255,255,0.8); /* 左上高光 */
}
.table-modern td, .table-modern th {
border: 1px solid #ddd;
padding: 10px 12px;
}
.table-modern thead th {
background: linear-gradient(180deg, #f8f9fa, #e9ecef);
box-shadow: inset 0 -1px 0 rgba(0,0,0,0.1);
}
優點:視覺層次豐富、支援圓角、動畫過渡、深色模式自動適配。
| 層級 | 選擇器 | 適用情境 |
|---|---|---|
| 表格外框 | table { border: 2px solid #333; } | 卡片式表格、報表邊界 |
| 儲存格內框 | td, th { border: 1px solid #ddd; } | 資料表格、網格 |
| 列分隔 | tr+tr td { border-top: 1px solid #eee; } | 極簡風格、僅橫線 |
| 欄分隔 | td+td { border-left: 1px solid #eee; } | 時間序列、財報 |
<style>
/* 1. 傳統 3D 邊框 */
.tbl-legacy { border-collapse:collapse; width:100%; }
.tbl-legacy td, .tbl-legacy th { border:3px solid; border-top-color:#369; border-left-color:#369; border-bottom-color:#036; border-right-color:#036; padding:8px; }
/* 2. 現代扁平 + 陰影 */
.tbl-flat { border-collapse:collapse; width:100%; box-shadow:0 2px 8px rgba(0,0,0,.08); border-radius:8px; overflow:hidden; }
.tbl-flat td, .tbl-flat th { border:1px solid #e5e7eb; padding:10px 12px; }
.tbl-flat thead th { background:#f3f4f6; font-weight:600; }
/* 3. 極簡橫線 */
.tbl-minimal { border-collapse:collapse; width:100%; }
.tbl-minimal th, .tbl-minimal td { border:none; border-bottom:1px solid #f0f0f0; padding:12px; text-align:left; }
.tbl-minimal thead th { border-bottom:2px solid #333; color:#333; font-weight:600; }
.tbl-minimal tbody tr:hover td { background:#fafafa; }
</style>
<h3>傳統 3D</h3><table class="tbl-legacy">...</table>
<h3>現代扁平</h3><table class="tbl-flat">...</table>
<h3>極簡橫線</h3><table class="tbl-minimal">...</table>
bordercolorlight、bordercolordarkborder-collapse:collapseinset/outset(快速)、逐側 border-*-color(精確)、box-shadow(現代)border-radius、overflow:hidden 實現圓角表格@media (prefers-color-scheme: dark) 調整邊框/陰影色拋棄棄用屬性,擁抱 CSS 邊框與陰影模組,不只相容性更好,更能創造出具備設計深度、響應式友善、深色模式自適應的現代化表格視覺體驗。