CSS

计数器复位 | counter-reset

counter-reset

counter-reset 重置一个CSS计数器值。计数器的值可以使用counter-increment增加或减少。

/* Set "my-counter" to 0 */ counter-reset: my-counter; /* Set "my-counter" to -1 */ counter-reset: my-counter -1; /* Set "counter1" to 1, and "counter2" to 4 */ counter-reset: counter1 1 counter2 4; /* Cancel any reset that could have been set in less specific rules */ counter-reset: none; /* Global values */ counter-reset: inherit; counter-reset: initial; counter-reset: unset;

初始值none
应用于all elements
是否继承no
媒体all
计算值as specified
Animation typediscrete
规范顺序the unique non-ambiguous order defined by the formal grammar

句法

counter-reset属性指定为下列任一项:

  • <custom-ident>命名计数器,随后可选择一个<integer>。您可以指定任意数量的计数器,以便根据需要进行重置,每个名称或名称编号对之间用空格分隔。

  • 关键字值none.

取值

<custom-ident>要重置的计数器的名称。

形式语法

[ <custom-ident> <integer>? ]+ | none

实例

h1 { counter-reset: chapter section 1 page; /* Sets the chapter and page counters to 0, and the section counter to 1 */ }

规格

SpecificationStatusComment
CSS Lists and Counters Module Level 3The definition of 'counter-reset' in that specification.Working DraftNo change.
CSS Level 2 (Revision 1)The definition of 'counter-reset' in that specification.RecommendationInitial definition.

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support2.0(Yes)1.018.09.23.11

FeatureAndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support2.1(Yes)25.0110110.03.2