首页 > Web开发 > 详细

CSS3 counter计数器

时间:2019-08-02 18:52:05      阅读:91      评论:0      收藏:0      [点我收藏+]

counter函数

它通常与伪元素一起使用,但理论上可以在支持值的任何地方使用

返回值

指定计数器当前的值

用法

counter(countername)

计数器的名字通过属性counter-incrementcounter-reset定义。

counter-increment属性

它的值包括两部分:第一个为计数器的名字,第二个值标识递增的值(默认为1),比如:

counter-increment:count 1  /*每次递增1*/

counter-increment:count 2  /*每次递增2*/

counter-reset属性

它的值包括两部分:第一部分为计数器的名字;第二部分为计数器的起始值(默认为0),比如:

counter-reset:count 0 /*从1开始计数*/

counter-reset:count 2 /*从3开始计数*/

counter-reset:count1 0 count2 1 count3 2/*声明了三个计数器count1,count2,count3*/

与content搭配使用

content主要是跟 :after, :before,::after,::before来搭配用的。

:after{

  content:conter(count)

}

整体例子

html:

<dl>

 <dt>example</dt>
 <dd>example</dd>
 <dd>example</dd>
 <dd>example</dd>
 <dt>example2</dt>
 <dd>example2</dd>
 <dd>example2</dd>
 <dd>example2</dd>
 <dd>example2</dd>
</dl>
css:
dl { counter-reset:test1 0;}
dt { counter-increment: test1counter-reset: test2 0;}
dt:before{ content:counter(test1)"、";}
dd{ counter-increment:test2;}
dd:before{
 content:counter(test1)"-"counter(test2)"、";
}
 

效果如下:

技术分享图片

 

CSS3 counter计数器

原文:https://www.cnblogs.com/embrace-ly/p/11290514.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!