字體屬性
| 屬性 | 值 | 說明 |
font-family | 字體名稱清單 | 以逗號分隔,建議最後加通用字體 sans-serif/serif |
font-style | normal | italic | oblique | 斜體/傾斜 |
font-weight | normal(400) | bold(700) | bolder | lighter | 100-900 | 數值對應字重,視字體支援度而定 |
font-size | 關鍵字 xx-small~xx-large / 相對 larger/smaller / 長度 / 百分比 | 預設 medium;建議用 rem 做根單位 |
font-variant | normal | small-caps | 小型大寫字母(英文專用) |
font | 綜合簡寫 | font: italic small-caps bold 16px/1.5 "Microsoft JhengHei";(順序固定:style variant weight size/line-height family) |
文字排版屬性
| 屬性 | 值 | 說明 |
line-height | normal | 數值(倍數) | 長度 | 百分比 | 建議用無單位數值(如 1.5),繼承為倍數而非像素 |
text-align | left | right | center | justify | 區塊容器內文字水平對齊 |
vertical-align | baseline | top | middle | bottom | sub | super | text-top | text-bottom | 長度/百分比 | 行內/表格單元格垂直對齊 |
text-decoration | none | underline | overline | line-through | blink | 文字裝飾線 |
text-transform | none | capitalize | uppercase | lowercase | 英文大小寫轉換 |
letter-spacing | normal | 長度(可負) | 字元間距 |
text-indent | 長度 | 百分比 | 首行縮排,僅適用區塊容器 |
實用範例:垂直置中單行文字
.v-center {
height: 200px;
line-height: 200px; /* 等於高度 */
vertical-align: middle;
text-align: center;
}
繼承與重置建議
- 上述大多數屬性 可繼承(
inherit 關鍵字可強制繼承)。
- 專案初期建議引入 Normalize.css 或自訂 Reset,統一跨瀏覽器預設樣式。
- 中英文混排時,先宣告英文字體再宣告中文字體:
font-family: "Helvetica Neue", "Microsoft JhengHei", sans-serif;。