| 屬性 | 值/範例 | 說明 | 繼承 |
|---|---|---|---|
font-family | "PingFang TC", "Microsoft JhengHei", sans-serif | 字體堆疊,逗號分隔備選 | 是 |
font-size | 16px, 1rem, clamp(1rem, 2vw, 1.5rem) | 字號,建議用相對單位 | 是 |
font-weight | normal/bold/100-900 | 粗細,Variable Font 支援任意值 | 是 |
font-style | normal, italic, oblique 10deg | 斜體/傾斜 | 是 |
font-stretch | condensed, expanded, 100% | 字寬(需字體支援) | 是 |
font-variant | small-caps, normal | 小型大寫字母 | 是 |
font | italic 600 1rem/1.5 "Font" | 簡寫:style variant weight stretch size/line-height family | 是 |
font-feature-settings | "liga" 1, "kern" 1, "tnum" 1 | OpenType 特性(合字、等寬數字等) | 是 |
font-variation-settings | "wght" 400, "wdth" 100 | Variable Font 軸控制 | 是 |
| 屬性 | 值/範例 | 說明 | 繼承 |
|---|---|---|---|
line-height | 1.5, 1.5rem, normal | 行高,無單位數值為乘數(推薦) | 是 |
text-align | left, center, right, justify, start, end | 水平對齊,start/end 邏輯屬性支援 RTL | 是 |
text-align-last | auto, center, justify | 最後一行/強制換行行的對齊 | 是 |
vertical-align | baseline, middle, top, bottom, sub, super, text-top, text-bottom, 10px | 行內元素垂直對齊基準 | 否 |
text-indent | 2em, 24px, -9999px | 首行縮排,負值常用隱藏文字 | 是 |
letter-spacing | 0.05em, 1px, -0.02em | 字符間距(追蹤) | 是 |
word-spacing | 0.25em, 4px | 單詞間距 | 是 |
white-space | normal, nowrap, pre, pre-wrap, pre-line, break-spaces | 空白處理與換行規則 | 是 |
word-break | normal, break-all, keep-all, break-word | 單詞斷行規則 | 是 |
overflow-wrap / word-wrap | normal, break-word, anywhere | 長詞溢出換行 | 是 |
hyphens | none, manual, auto | 自動連字符斷詞(需 lang 屬性) | 是 |
writing-mode | horizontal-tb, vertical-rl, vertical-lr, sideways-rl | 文字書寫方向 | 是 |
text-orientation | mixed, upright, sideways | 直排時字符朝向 | 是 |
| 屬性 | 值 | 說明 |
|---|---|---|
text-decoration | underline, overline, line-through, blink, none | 簡寫:line style color thickness |
text-decoration-line | underline 等 | 線條位置 |
text-decoration-style | solid, double, dotted, dashed, wavy | 線條樣式 |
text-decoration-color | red, currentColor | 線條顏色 |
text-decoration-thickness | 2px, 0.1em, auto | 線條粗細 |
text-decoration-skip-ink | auto, none | 下劃線避開下延筆畫 |
text-transform | uppercase, lowercase, capitalize, full-width, full-size-kana, none | 大小寫轉換 |
text-shadow | 2px 2px 4px rgba(0,0,0,0.3) | 陰影:x y blur color,可多層逗號分隔 |
text-overflow | clip, ellipsis, "…" | 溢出省略標記(需配合 overflow:hidden, white-space:nowrap) |
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; 零下載、原生渲染。font-size: clamp(1rem, 2vw + 0.5rem, 2rem); 無媒體查詢自適應。line-height: 1.5; 子元素繼承乘數而非固定像素,避免行高崩壞。margin-inline-start, padding-block, border-inline-end 等,自適應 RTL/LTR。--font-sans: ...; --text-base: 1rem; --leading-relaxed: 1.625;。/* 截斷單行文字 */
.truncate {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
/* 截斷多行文字 (WebKit/Blink) */
.line-clamp-3 {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
/* 強制不換行、超出顯示省略 */
.nowrap-ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* 保留空白與換行(如代碼、詩歌) */
.pre-wrap { white-space: pre-wrap; }
/* 文字選取樣式 */
::selection { background: var(--brand-primary); color: #fff; }
CSS 文字屬性涵蓋字體選擇、度量、排版、裝飾、轉換、溢出處理全鏈路。現代開發應:優先系統字體、相對單位、無單位行高、邏輯屬性、CSS 變數管理設計 Token,配合 clamp() 實現流體排版,用 text-overflow/line-clamp 處理截斷,構建可維護、無障礙、跨語言友善的文字系統。