--- title: counter-increment slug: Web/CSS/counter-increment translation_of: Web/CSS/counter-increment ---
{{CSSRef}}

概要

counter-increment属性用于将CSS Counters的值增加给定值。可以使用 {{cssxref("counter-reset")}} 属性重置计数器的值。

{{cssinfo}}

语法

/* Increment counter-name by 1 */
counter-increment: counter-name;

/* Decrement counter-name by 1 */
counter-increment: counter-name -1;

/* Increment counter1 by 1, and decrement counter2 by 4 */
counter-increment: counter 1 counter2 -4;

/* Do not increment/decrement anything: used to hide less specific values */
counter-increment: none;

/* Global values */
counter-increment: inherit;
counter-increment: initial;
counter-increment: unset;

可选值

{{cssxref("custom-ident", "<custom-ident>")}}
递增的计数器的名称。该标识符由不区分大小写的字母a到z,数字0到9,下划线(_)和/或短划线( - )的组合组成。第一个非破折号字符必须是一个字母(即,在它的开头没有数字,即使前面有破折号。)此外,在标识符的开头禁止使用两个破折号。在任何案例组合中都不能是none,unset,initial或inherit。
{{cssxref("<integer>")}}
计数器的值。如果没有给出,默认为1。
none
不得增加计数器。用作默认值,或取消更具体规则的增量。

你可以根据需要指定要递增的计数器,每个计数器用空格分隔。

语法形式

{{csssyntax}}

示例

h1 {
  counter-increment: chapter section 2 page;
  /* Increases the value of the chapter and page counters by 1
     and the section counter by 2. */
}

规范

Specification Status Comment
{{ SpecName('CSS3 Lists', '#counter-increment', 'counter-increment') }} {{ Spec2('CSS3 Lists') }} No change.
{{SpecName('CSS2.1', 'generate.html#propdef-counter-increment', 'counter-increment')}} {{Spec2('CSS2.1')}} Initial definition.

浏览器兼容性

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 2.0 1.0 (?) 8.0 9.2 3.0 (?)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

参考