大网数据广告活动
Web 标准与前端开发

`negative` CSS at-rule descriptor

· 52CE 我爱测

The **`negative`** descriptor of the @counter-style at-rule lets you define how negative counter values are represented when defining custom counter styles. The value of the `negative` descriptor defines the symbols to be added before and after the counter representation when the

The negative descriptor of the @counter-style at-rule lets you define how negative counter values are represented when defining custom counter styles. The value of the negative descriptor defines the symbols to be added before and after the counter representation when the counter's value is negative.

Syntax

/* One <symbol> value */
negative: "--"; /* Adds '--' before if counter value is negative */

/* Two <symbol> values */
negative: "(" ")"; /* Adds '(- before and ')' after if counter value is negative */

Values

The negative descriptor accepts up to two <symbol> values.

  • <symbol>
    • : If only one value is specified, it is added before the counter representation when the counter is negative. If two values are specified, the first one is added before and the second one is added after the counter representation when the counter is negative.

Description

If the counter value is negative, the specified <symbol> for the negative descriptor is added before the counter representation, replacing the default - for negative values. The second <symbol>, if specified, is added after the counter representation.

The negative descriptor is relevant in two cases: if counter styles have the system value of symbolic, alphabetic, numeric, and additive and the count is negative; and if system value is extends and the extended counter style itself uses a negative sign. For systems that don't support negative counter values, specifying the negative descriptor has no effect and is ignored.

Formal definition

Formal syntax

Examples

Rendering negative counters

This example extends the decimal list style. The negative descriptor is used to add (- and ) before and after negative counter values.

HTML

<ol start="-3">
  <li>Negative three</li>
  <li>Negative two</li>
  <li>Negative one</li>
  <li>Zero</li>
  <li>One</li>
</ol>

CSS

@counter-style neg {
  system: extends decimal;
  negative: "(-" ")";
  suffix: ": ";
}

ol {
  list-style: neg;
}

Result

Rendering negative counters

The prefix and suffix listed as the value of the negative descriptor are only added to the marker when the counter value is less than zero.

Specifications

Browser compatibility

See also

  • @counter-style descriptors: @counter-style/system, @counter-style/symbols, @counter-style/additive-symbols, @counter-style/prefix, @counter-style/suffix, @counter-style/range, @counter-style/pad, @counter-style/speak-as, @counter-style/fallback
  • List style properties: list-style, list-style-image, list-style-position
  • symbols() function to create anonymous counter styles
  • CSS counter styles module
  • CSS lists and counters module

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。