--- title: counter-reset slug: Web/CSS/counter-reset translation_of: Web/CSS/counter-reset ---
counter-reset 属性用于将 CSS计数器 重置为制定值
{{EmbedInteractiveExample("pages/css/counter-reset.html")}}
注意:计数器的值能够通过 CSS 属性 {{cssxref("counter-increment")}} 控制递增或递减。
/* Set counter-name to 0 */ counter-reset: counter-name; /* Set counter-name to -1 */ counter-reset: counter-name -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;
counter-reset 属性可以指定为以下之一:
<自定义 ID> [<数值>]。您可以指定任意数量的计数器进行重置,每个名称或“名称-数字”对之间用空格分隔。none。该名称由不区分大小写的字母 a 到 z,数字 0 到 9,下划线(_)和 / 或短划线( - )的组合组成,并且第一个非破折号字符必须是一个字母(即,在它的开头没有数字,即使前面有破折号)。此外,在标识符的开头禁止使用两个破折号。在任何案例组合中都不能是 none,unset,initial 或 inherit。
0。noneh1 {
counter-reset: chapter section 1 page;
/* Sets the chapter and page counters to 0
and the section counter to 1. */
}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('CSS3 Lists', '#counter-reset', 'counter-reset')}} | {{Spec2('CSS3 Lists')}} | No change. |
| {{SpecName('CSS2.1', 'generate.html#propdef-counter-reset', 'counter-reset')}} | {{Spec2('CSS2.1')}} | Initial definition. |
{{cssinfo}}