css计数器

计数器通过设置一个变量,根据规则递增变量,可用于自动编号

counter-set:创建或者重置计数器(后面即为变量)

counter-increment:递增变量

content:插入生成的内容

counter()/counters():将计数器的值添加到元素

比如:

<style>
body {
  counter-reset: section;
}

h2::before {
  counter-increment: section;
  content: "Section " counter(section) ":";
}
</style>

这里的变量为section,在每个<h2>元素之前会添加"Section i:"

 

计数器可嵌套

 

counters()用于在不同的嵌套层级中插入字符串

posted @ 2022-04-30 21:31  树叶本子  阅读(48)  评论(0)    收藏  举报