类别 | 说明 |
---|---|
counter-reset | 创建;默认从0开始;初始化计数器
多个计数器使用空格分割 可以使用变量 |
counter-increment | 计数 |
counter() | 在伪元素的 content 属性中获取并显示
设置计数器样式 |
类别 | 说明 |
---|---|
disc | 默认实心圆 |
circle | 标记是空心圆 |
square | 标记是实心方块 |
decimal | 普通数字 |
decimal-leading-zero | 0开头的数字标记:01, 02, 03 |
lower-roman | 小写罗马数字:i, ii, iii, iv, v |
upper-roman | 大写罗马数字:I, II, III, IV, V |
lower-alpha | 小写英文字母:a, b, c, d, e |
upper-alpha | 大写英文字母:A, B, C, D, E |
counter-reset: percent;
counter-reset: percent 10;
counter-reset: percent var(--per);
counter-reset: chapter-sn;
counter-reset: tbl-sn img-sn exam-sn;
ol { counter-reset: li-sn; } ol li { counter-increment: li-sn; } ol li::before { content: counter(li-sn); color: #fff; margin-right: 1em; padding: 0 4px; background-color: var(--main-color); }
<pre> <span>hello, world.</span> </pre>
pre { counter-reset: sn; } pre span { counter-increment: sn; } pre span::before { content: counter(sn, decimal-leading-zero)' '; }
.article { counter-reset: chap; } .article h2 { counter-reset: sec;//每章的分节都重新编号 counter-increment: chap; } .article h2::before { content: '第' counter(chap)'章 '; } .article h3 { counter-increment: sec; } .article h3::before { content: counter(chap)'.' counter(sec)'节 '; }
body { counter-reset: tbl-sn img-sn; } /* table */ table { counter-increment: tbl-sn; } table caption::before { content: '表' counter(tbl-sn)' '; } /* figure */ figure { counter-increment: img-sn; } figure figcaption::before { content: '图' counter(img-sn)' '; }
@counter-style counter-style-name { system: 类型 decimal | alpha | symbols; symbols: 符号序列; suffix: 后缀;每个计数后面的字符串; range: 有效范围; fallback: 超出范围时使用的备用计数器,counter-style-name; speak-as: 控制语音合成器如何读出计数 speaking-rule; } .custom-ul>li { list-style-type: my-style; }