list-style: ;
/* 順序任意,缺省值:disc outside none */
| 分類 | 關鍵字 | 效果 | 適用列表 |
|---|---|---|---|
| 無序 | disc | 實心圓 ● (默認) | ul |
circle | 空心圓 ○ | ul | |
square | 實心方塊 ■ | ul | |
none | 無標記 | ul/ol | |
| 有序 | decimal | 阿拉伯數字 1,2,3... | ol |
lower-roman | 小寫羅馬 i, ii, iii... | ol | |
upper-roman | 大寫羅馬 I, II, III... | ol | |
lower-alpha | 小寫字母 a, b, c... | ol | |
upper-alpha | 大寫字母 A, B, C... | ol | |
cjk-ideographic | 中文數字 一、二、三... | ol | |
hiragana/katakana | 日文平/片假名 | ol |
ul.custom-bullets {
list-style-image: url('bullet.svg'); /* SVG 矢量無失真 */
/* 回退:圖片失效時顯示 list-style-type */
}
li::marker { /* 現代方式:直接控制標記盒模型 */
content: url('bullet.svg');
font-size: 1.2em;
color: #0066cc;
}
💡 **現代首選 ::marker 偽元素**:支援顏色、字號、動畫、SVG,完全脫離 list-style-image 限制。
| 值 | 行為 | 視覺效果 |
|---|---|---|
outside (默認) | 標記在內容盒外側,文字不環繞標記對齊 | 標記懸空於左邊距外 |
inside | 標記在內容盒內側,文字環繞對齊 | 標記併入首行文本流 |
⚠️ margin-left: 0 會導致 outside 標記不可見,需保留足夠 padding-left (通常 ≥ 1.5rem)。
/* reset.css */
ul, ol, menu {
list-style: none;
padding: 0;
margin: 0;
}
/*** 文章正文列表 ***/
.prose ul { list-style: disc outside; padding-left: 1.5rem; }
.prose ol { list-style: decimal outside; padding-left: 1.5rem; }
/*** 導航/選單 — 無標記 ***/
.nav { list-style: none; display: flex; gap: 1rem; }
/*** 自定義圖標列表 — ::marker 現代寫法 ***/
.feature-list li::marker {
content: "✨";
color: #f59e0b;
font-size: 1.2em;
}
.numbered-section {
counter-reset: section;
}
.numbered-section h2::before {
counter-increment: section;
content: counter(section) ". ";
font-weight: bold;
color: #0066cc;
}
適用於文檔章節編號、法律條文、多級嵌套編號 (counter-reset: subsection 於 h3)。
list-style 是**語義化列表的標準控制接口**。現代開發:**Reset 歸零 → 組件層語義化重建 → ::marker 進階定製 → CSS Counters 複雜編號**。拒絕直接在業務組件寫 ul { list-style: ... },建立可復用的列表組件體系。