counter-reset - 创建或重置计数器
counter-increment - 增加计数器值
content - 插入生成的内容
counter()或counters()函数 - 将计数器的值添加到元素
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "选项 " counter(section) ": ";
}
body {
counter-reset: section;
}
h1 {
counter-reset: subsection;
}
h1::before {
counter-increment: section;
content: "Section " counter(section) ". ";
}
h2::before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
计数器也可用于制作轮廓列表,因为在子元素中会自动创建计数器的新实例。这里我们使用counters()函数在不同级别的嵌套计数器之间插入一个字符串:ol {
counter-reset: section;
list-style-type: none;
}
li::before {
counter-increment: section;
content: counters(section,".") " ";
}
属性 | 描述 |
---|---|
content | 与::before和::after伪元素一起使用,插入生成的内容 |
counter-increment | 递增一个或多个计数器值 |
counter-reset | 创建或重置一个或多个计数器 |