--- title: '@counter-style' slug: Web/CSS/@counter-style translation_of: Web/CSS/@counter-style ---
{{ CSSRef() }}
@counter-style是一个
CSS at-rule ,它让开发者可以自定义counter的样式。 一个 @counter-style规则
定义了如何把一个计数器的值转化为字符串表示。
最初版的CSS定义了一系列很好用的计数器样式, 尽管近几年又添加了很多样式,但是这种限制方式被证明已经不能满足全球化的排版了。@counter-style规则用一种开放的方式弥补了这一缺点,在预定义的样式不能满足需求时,它可以使开发者自定义他们自己的计数器样式。
@counter-style <counter-style-name> { system: <counter system> symbols: <counter symbols> additive-symbols: <additive-symbols> negative: <negative symbol> prefix: <prefix> suffix: <suffix> range: <range> pad: <padding> speak-as: <speak-as> fallback: <counter-style-name> }
每个 @counter-style
由一个名称标识并具有一组描述符
@counter-style winners-list { system: fixed; symbols: url(gold-medal.svg) url(silver-medal.svg) url(bronze-medal.svg); suffix: " "; }
@counter-style circled-alpha { system: fixed; symbols: Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ; suffix: " "; }
上面的counter style规则在列表中可以如下使用:
.items { list-style: circled-alpha; }
会产生如下列表:
Ⓐ One
Ⓑ Two
Ⓒ Three
Ⓓ Four
Ⓔ FIve
....
...
Ⓨ Twenty Five
Ⓩ Twenty Six
27 Twenty Seven
28 Twenty Eight
29 Twenty Nine
30 Thirty
查看更多例子 demo page.
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Counter Styles', '#the-counter-style-rule', 'counter-style')}} | {{Spec2('CSS3 Counter Styles')}} | Initial definition. |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatGeckoDesktop(33)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatGeckoDesktop(33)}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |