css学习之 counter属性详解

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css学习之 counter属性详解相关的知识,希望对你有一定的参考价值。

学习css ,counter属性不得不了解清楚,css counter属性被几乎所有浏览器(包括IE8)支持, 但是却不常使用。本文和大家分享的就是counter属性相关内容,虽然这个属性不常用,但是希望大家需要用的时候,本文对大家有所帮助。
COUNTER-RESET
明译为计数器重置。形如: counter-reset: counter-name
常见写法为
/* Set counter-name to 0 */
counter-reset: counter-name;
/* Set counter-name to -1 */
counter-reset: counter-name -1;
/* Set counter1 to 1, and counter2 to 4 */
counter-reset: counter1 1 counter2 4;
用于在某个元素上重置counter
COUNTER-INCREMENT
couter-increment 明译为计数器重置
常用写法为
/* Increment counter-name by 1 */counter-increment: counter-name;
/* Decrement counter-name by 1 */counter-increment: counter-name -1;
/* Increment counter1 by 1, and decrement counter2 by 4 */counter-increment: counter 1 counter2 -4;
在使用 counter-increment 之前 我们必须先使用 counter-reset 在其父元素初始化一个counter
例如:
// parent element has a counter-reset// applied to instantiate itsection {
counter-reset: unicornCounter;
}
// specify the child element being countedsection h1 {
counter-increment: unicornCounter;
}
在上面的代码里 section的每一个h1元素 将会被设置counted值1
css语法规则
COUNTER-RESET 和 COUNTER-INCREMENT 的语法类似
第一位 表示具体counter标识
可以是a-z 0-9 _ - 组合的单词 但不能是关键字none, unset, initial, or inherit


来源:网络

以上是关于css学习之 counter属性详解的主要内容,如果未能解决你的问题,请参考以下文章

python学习之web中css

python学习之CSS

css3学习之--transition属性(过渡)

前端学习之CSS

前端学习之CSS

Html学习之八(CSS选择器的使用--属性选择器)