<font color="red" size="3" face="Arial"> 在 HTML5 中已移除,瀏覽器雖兼容但不保證未來支援。請改用 CSS。
| 單位類型 | 語法範例 | 說明 |
|---|---|---|
| 關鍵字 | color: red; color: transparent; | 16 基本色 + 131 擴展色名,不透明度無法控制 |
| 十六進制 | color: #ff0000; color: #f00; color: #ff000080; (8 位含 alpha) | #RRGGBB、#RGB、#RRGGBBAA、#RGBA |
| RGB/RGBA | color: rgb(255,0,0); color: rgba(255,0,0,0.5); | 0-255 或 0%-100%,alpha 0-1 |
| HSL/HSLA | color: hsl(0,100%,50%); color: hsla(0,100%,50%,0.5); | 色相 0-360、飽和度%、亮度%,直覺調色 |
| HWB | color: hwb(0 0% 0%); | 色相、白度、黑度 (CSS Color Level 4) |
| LCH / Lab | color: lch(53.23% 104.55 40.5); | 感知均勻色彩空間 (CSS Color Level 4) |
| color() 函數 | color(display-p3 1 0 0); | 指定色域 (P3, Rec2020 等) |
:root {
--brand-primary: #2c3e50;
--brand-accent: #e74c3c;
--text-main: #333;
--text-muted: #666;
}
body { color: var(--text-main); }
h1, h2, h3 { color: var(--brand-primary); }
.btn-primary { color: #fff; background: var(--brand-primary); }
.btn-danger { color: #fff; background: var(--brand-accent); }
.text-muted { color: var(--text-muted); }
| 屬性 | 用途 | 範例 |
|---|---|---|
| font-family | 字體堆疊 | font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif; |
| font-size | 字號 | font-size: 1rem; (建議用 rem/em) |
| font-weight | 粗細 | font-weight: 700; (normal=400, bold=700) |
| font-style | 斜體 | font-style: italic; |
| line-height | 行高 | line-height: 1.6; (無單位為倍數) |
| text-align | 水平對齊 | text-align: center; |
| text-decoration | 底線/刪除線 | text-decoration: underline; |
| text-transform | 大小寫轉換 | text-transform: uppercase; |
| letter-spacing | 字距 | letter-spacing: 0.05em; |
| word-spacing | 詞距 | word-spacing: 0.2em; |
<h1 class="text-center">主標題置中</h1>
<h2 class="text-right">副標題靠右</h2>
.text-center { text-align: center; }
.text-right { text-align: right; }
優於 <h1 align="center">(已棄用)。
[data-theme="dark"] {
--text-main: #e0e0e0;
--brand-primary: #3498db;
}
搭配 JS 切換 document.documentElement.dataset.theme 實現深色模式。