问题描述
如此处定义:
您可以使用像
H1:before {
content:章节计数器(章)。
counter-increment:chapter; / *添加1到章节* /
}
H1 {
counter-reset:section; / *将section设置为0 * /
}
H2:before {
content:counter(chapter)。计数器(区);
counter-increment:section;
}
有一种方法可以使用相同的代码来增加字母,如a
是, counter()
的第二个参数定义了所使用的计数器的类型, list-style-type
从常规
ul
或 ol
;例如:
content:counter(chapter,lower-alpha);
ul {counter-reset:listStyle;} ul li {margin-left:1em; counter-increment:listStyle;} ul li :: before {margin-right:1em; content:counter(listStyle,lower-alpha);}
< ul> < li>一个< / li> < li>两个< / li> < li>三个< / li>< / ul>
。
其他包括: decimal
, decimal-leading-zero
, lower-roman
code> upper-roman , lower-greek
, lower-latin
upper-latin
, armenian
, georgian
, lower-alpha
, upper-alpha
>
- 。
As defined here:
http://www.w3.org/TR/CSS21/generate.html#propdef-counter-increment
You can use code like the following to increment numbers in pseudo elements.
H1:before {
content: "Chapter " counter(chapter) ". ";
counter-increment: chapter; /* Add 1 to chapter */
}
H1 {
counter-reset: section; /* Set section to 0 */
}
H2:before {
content: counter(chapter) "." counter(section) " ";
counter-increment: section;
}
Is there a way you can use the same code to increment letters like "a", "b", "c", etc?
Thank you!
Yes, the second argument to counter()
defines the type of counter used, as for the list-style-type
from a regular ul
or ol
; for example:
content: counter(chapter, lower-alpha);
ul {
counter-reset: listStyle;
}
ul li {
margin-left: 1em;
counter-increment: listStyle;
}
ul li::before {
margin-right: 1em;
content: counter(listStyle, lower-alpha);
}
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
Others include: decimal
, decimal-leading-zero
, lower-roman
, upper-roman
, lower-greek
, lower-latin
, upper-latin
, armenian
, georgian
, lower-alpha
, upper-alpha
References:
这篇关于CSS伪元素计数器:可以递增字母“a”,“b”,“c”等而不是数字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!