negative
@counter-style at-rule 的 negative 描述符允许你定义在定义自定义计数器样式时,负计数器值的表示方式。negative 描述符的值定义了当计数器值为负时,要添加到计数器表示之前和之后的符号。
语法
css
/* One <symbol> value */
negative: "--"; /* Adds '--' before if counter value is negative */
/* Two <symbol> values */
negative: "(" ")"; /* Adds '(- before and ')' after if counter value is negative */
值
negative 描述符接受最多两个 <symbol> 值。
<symbol>-
如果只指定一个值,则当计数器为负时,它会被添加到计数器表示之前。如果指定两个值,则第一个值会在计数器为负时添加到计数器表示之前,第二个值会添加到计数器表示之后。
描述
如果计数器值为负,则 negative 描述符指定的 <symbol> 会添加到计数器表示之前,替换负值默认的 -。第二个 <symbol>(如果指定)会添加到计数器表示之后。
negative 描述符在两种情况下相关:如果计数器样式具有 symbolic、alphabetic、numeric 和 additive 的 system 值且计数为负;以及如果 system 值为 extends 且扩展的计数器样式本身使用负号。对于不支持负计数器值的系统,指定 negative 描述符没有效果并会被忽略。
正式定义
| 相关的 at-rule | @counter-style |
|---|---|
| 初始值 | "-" 连字符-减号 |
| 计算值 | 同指定值 |
正式语法
negative =
<symbol> <symbol>?
<symbol> =
<string> |
<image> |
<custom-ident>
<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>
<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )
<image-set()> =
image-set( <image-set-option># )
<cross-fade()> =
cross-fade( <cf-image># )
<element()> =
element( <id-selector> )
<image-tags> =
ltr |
rtl
<image-src> =
<url> |
<string>
<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?
<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?
<id-selector> =
<hash-token>
示例
渲染负计数器
此示例扩展了decimal列表样式。negative描述符用于在负计数器值之前和之后添加(-和)。
HTML
html
<ol start="-3">
<li>Negative three</li>
<li>Negative two</li>
<li>Negative one</li>
<li>Zero</li>
<li>One</li>
</ol>
CSS
css
@counter-style neg {
system: extends decimal;
negative: "(-" ")";
suffix: ": ";
}
ol {
list-style: neg;
}
结果
规范
| 规范 |
|---|
| CSS Counter Styles Level 3 # counter-style-system |
浏览器兼容性
加载中…
另见
@counter-style描述符:system、symbols、additive-symbols、prefix、suffix、range、pad、speak-as、fallback- 列表样式属性:
list-style、list-style-image、list-style-position symbols()函数用于创建匿名计数器样式- CSS 计数器样式模块
- CSS 列表和计数器模块