只需在 <table> 加上 class="table",無需對 <tr>、<td> 逐個加 Class,極大降低 HTML 耦合與維護成本。
<link rel="stylesheet" href="./css/table.css" />
<table class="table" style="width: 600px">...</table>
/* 表格基礎 */
.table { width: 100%; padding: 0; margin: 0; font-family: Arial, Tahoma, Verdana, Sans-Serif, "Microsoft YaHei"; border-left: 1px solid #add8e6; border-collapse: collapse; }
/* 表頭 */
.table th { font-size: 12px; font-weight: 600; color: #303030; border-right: 1px solid #add8e6; border-bottom: 1px solid #add8e6; border-top: 1px solid #add8e6; letter-spacing: 2px; text-align: center; padding: 10px 0; background: url(../images/tablehdbg.png); white-space: nowrap; overflow: hidden; }
/* 單元格 */
.table td { border-right: 1px solid #add8e6; border-bottom: 1px solid #add8e6; background: #fff; font-size: 12px; padding: 3px 3px 3px 6px; color: #303030; word-break: break-all; word-wrap: break-word; white-space: normal; }
/* 隔行變色(手動加 class="color") */
.table td.color { background: #edf7f9; }
/* 連結樣式 */
.table td a:link, .table td a:visited { font-weight: 400; color: #2259d7; text-decoration: none; }
.table td a:hover { text-decoration: underline; color: #303030; }
.table td a:active { color: #2259d7; }
#add8e6 替換為目標色值。.table、.table th、.table td 三組規則。.table tr:nth-child(even) td { background: #edf7f9; } 純 CSS 實現,無需手動加 Class。