CSS counter-increment 属性

定义

counter-increment 属性设置某个选取器每次出现的计数器增量。默认增量是 1。

注释:如果使用了 "display: none",则无法增加计数。如使用 "visibility: hidden",则可增加计数。

继承性:No

说明

利用这个属性,计数器可以递增(或递减)某个值,这可以是正值或负值。如果没有提供 number 值,则默认为 1。

JavaScript 语法

CSS 属性也可通过一段 JavaScript 被动态地改变。

脚本语法:

object.style.counterIncrement="section 2"

在我们的 HTML DOM 教程中,您也可以找到完整的 Style 对象参考手册

例子

A way to number sections with "Section 1", "Section 2", "Section 3"etc.: 
h1:before 
{
content: "Section " counter(section) " ";
/* Add 1 to section */
counter-increment: section; 
}

A way to number sections with "Section 1", "Section 3", "Section 5" etc.:

h1:before 
{
content: "Section " counter(section) " ";
/* Add 2 to section */
counter-increment: section 2; 
}

可能的值

描述
none 默认。选择器无计数器增量。
identifier number

identifier 定义将增加计数的选择器、id 或 class。

number 定义增量。number 可以是正数、零或者负数。