CSS伪元素计数器:可以递增字母“a”,“b”,“c”等而不是数字吗? [英] CSS Pseudo Element Counters: can you increment an alphabet letter "a", "b", "c", etc instead of a number?

查看:250
本文介绍了CSS伪元素计数器:可以递增字母“a”,“b”,“c”等而不是数字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如此处定义:



http://www.w3.org/TR/CSS21/generate.html#propdef-counter-increment



您可以使用像

  H1:before {
content:章节计数器(章)。
counter-increment:chapter; / *添加1到章节* /
}
H1 {
counter-reset:section; / *将section设置为0 * /
}
H2:before {
content:counter(chapter)。计数器(区);
counter-increment:section;
}

有一种方法可以使用相同的代码来增加字母,如a

解决方案

div>

是, 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>  



JS Fiddle演示



其他包括: 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>

JS Fiddle demo.

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”等而不是数字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆