| 屬性 | 作用 | 典型值 |
|---|---|---|
counter-reset | 創建/重置計數器 | section 0, item -1 |
counter-increment | 遞增計數器 | section 1, item (默認+1) |
content | 偽元素顯示計數器值 | counter(section) "." counter(item) |
.numbered { list-style: none; counter-reset: item; } .numbered li::before { counter-increment: item; content: counter(item) ". "; font-weight: bold; color: #666; }
- Item A
- Item B
- Item C
.nested { list-style: none; counter-reset: level1; } .nested > li { counter-reset: level2; } .nested > li::before { counter-increment: level1; content: counter(level1) " "; } .nested ol > li::before { counter-increment: level2; content: counter(level1) "." counter(level2) " "; }
- Chapter 1
- Section 1.1
- Section 1.2
- Chapter 2
- Section 2.1
.nested li::before {
content: counters(item, ".") " "; /* 自動串聯所有祖先層級 */
}
.nested {
counter-reset: item -1; /* 從 0 開始,抵消根 li 的 +1 */
}
counters(name, separator, style) 會遍歷當前元素所有祖先的同名計數器,用分隔符連接。
Getting Started
Installation
Configuration
Advanced Usage
Custom Themes
Plugins