letter-spacing 控制字符間距,text-align 控制文本對齊,list-style-type 定義列表項標記。三大屬性構成文字排版的核心視覺控制。本文系統整理語法、取值與實戰技巧。
letter-spacing:字符間距
/* 語法 */
letter-spacing: normal | | inherit;
/* 實戰值 */
letter-spacing: 0; /* 默認,無額外間距 */
letter-spacing: 1px; /* 字符間增加 1px */
letter-spacing: 0.1em; /* 相對字體大小,推薦 */
letter-spacing: -0.5px; /* 負值:緊湊效果,標題常用 */
letter-spacing: 2px; /* 強調標題、Logo 字符拉開 */
關鍵特性
- 可繼承:子元素繼承父元素計算值
- 可為負值:緊湊排版,但過大負值導致字符重疊
- 影響文本測量寬度:
width: max-content 會包含間距
- 不影響詞間距(
word-spacing 控制單詞間距)
text-align:文本對齊
| 值 |
效果 |
適用元素 |
備註 |
left |
左對齊(LTR 文本) |
塊級容器 |
默認值 |
right |
右對齊 |
塊級容器 |
RTL 文本默認 |
center |
居中對齊 |
塊級容器 |
標題、按鈕、居中佈局 |
justify |
兩端對齊(調整詞間距) |
塊級容器 |
最後一行不調整,需 text-align-last: justify |
start |
邏輯開始端(LTR=left, RTL=right) |
塊級容器 |
邏輯屬性,國際化友好 |
end |
邏輯結束端 |
塊級容器 |
邏輯屬性 |
match-parent |
繼承父元素邏輯值並解析 |
塊級容器 |
解決繼承邏輯值問題 |
進階對齊控制
/* 最後一行對齊 */
.text-justify {
text-align: justify;
text-align-last: center; /* 最後一行居中 */
}
/* 垂直對齊(行內/表格單元格) */
.vertical-middle { vertical-align: middle; }
.vertical-top { vertical-align: top; }
.vertical-bottom { vertical-align: bottom; }
.vertical-baseline { vertical-align: baseline; } /* 默認 */
/* 文字方向 */
.ltr { direction: ltr; }
.rtl { direction: rtl; }
list-style-type:列表項標記大全
| 類別 |
值 |
效果示例 |
| 無/基礎 |
none |
無標記(重置常用) |
disc |
● 實心圓(默認) |
circle |
○ 空心圓 |
| 數字 |
decimal |
1, 2, 3... |
decimal-leading-zero |
01, 02, 03... |
| 羅馬數字 |
lower-roman |
i, ii, iii, iv, v... |
upper-roman |
I, II, III, IV, V... |
| 字母 |
lower-alpha / lower-latin |
a, b, c, d, e... |
upper-alpha / upper-latin |
A, B, C, D, E... |
lower-greek |
α, β, γ... |
cjk-ideographic |
中文數字:一、二、三... |
| 日文 |
hiragana / hiragana-iroha |
あ、い、う... / い、ろ、は... |
|
katakana / katakana-iroha |
ア、イ、ウ... / イ、ロ、ハ... |
| 其他 |
hebrew / armenian / georgian |
希伯來/亞美尼亞/喬治亞傳統編號 |
現代最佳實踐
/* 1. 重置列表樣式 */
ul, ol { list-style: none; padding: 0; margin: 0; }
/* 2. 自定義計數器(複雜嵌套編號) */
ol { counter-reset: section; }
li::before {
counter-increment: section;
content: counters(section, ".") " ";
}
/* 3. 字符間距響應式 */
h1 { letter-spacing: clamp(-0.5px, -0.02em, -1px); } /* 大標題緊湊 */
.body-text { letter-spacing: 0.02em; } /* 正文微調提升可讀性 */
/* 4. 邏輯屬性國際化 */
.container { text-align: start; } /* 自適應 LTR/RTL */
避坑指南
- ❌
letter-spacing 過大(> 0.5em)破壞詞識別,影響閱讀
- ❌
text-align: justify 窄容器中產生巨大詞間距(“河流效應”)
- ✅ 中文不需要
text-align: justify,字符本身等寬
- ✅
list-style-position: inside 讓標記參與文本流佈局
- ✅ 自定義標記用
::marker 偽元素(現代)或 ::before + content