counter-set
版本: CSS3
counter-set CSS属性将CSS计数器设置为给定值。它操作现有计数器的值,并且只在元素上没有给定名称的计数器时创建新计数器。
示例
/* Set "my-counter" to 0 */ counter-set: my-counter; /* Set "my-counter" to -1 */ counter-set: my-counter -1; /* Set "counter1" to 1, and "counter2" to 4 */ counter-set: counter1 1 counter2 4; /* Cancel any counter that could have been set in less specific rules */ counter-set: none; /* Global values */ counter-set: inherit; counter-set: initial; counter-set: unset;
浏览器支持
![]() |
![]() |
![]() |
![]() |
![]() |
IE8以上版本的浏览器都支持
counter-set
|
语法
counter-set :[ <custom-ident> <integer> ?]+| none
取值
- <custom-ident> :递增的计数器的名称。该标识符由不区分大小写的字母 a~z ,数字 0~9 ,下划线( _ )和/或短划线( - )的组合组成。第一个非破折号字符必须是一个字母(即,在它的开头没有数字,即使前面有破折号。)此外,在标识符的开头禁止使用两个破折号。在任何案例组合中都不能是 none , unset , initial 或 inherit 。
- <integer> :计数器的值。如果没有给出,默认为0。
- none :该关键字表示不执行计数器重置。它可用于重置隐藏在不太具体的规则中定义的计数器。你可以指定要根据需要重置的计数器,每个计数器用空格分隔。
实例
h1 { counter-set: chapter section 1 page; /* Sets the chapter and page counters to 0, and the section counter to 1 */ }