使用 CSS 计数器

您所在的位置:网站首页 css中的list-style 使用 CSS 计数器

使用 CSS 计数器

#使用 CSS 计数器| 来源: 网络整理| 查看: 265

计数器的值可以使用 counter() 或 counters() 函数以在 content 属性中显示。

例如,以下使用 counter() 声明的计数器会在每一个 h3 标题前面添加文本 Section :,其中的 是十进制计数的值(默认显示样式):

css

h3::before { counter-increment: section; /* Increment the value of section counter by 1 */ content: "Section " counter(section) ": "; /* Display counter value in default style (decimal) */ }

当不需要包含父级上下文的编号,而仅需要嵌套内容的编号时,应使用 counter() 函数。例如,以下示例的每一个嵌套内容的计数都从 1 开始:

1 One 1 Nested one 2 Nested two 2 Two 1 Nested one 2 Nested two 3 Nested three 3 Three

当需要同时包含父级上下文和嵌套内容的编号时,应使用 counters() 函数。例如,以下示例的每一个嵌套内容会包含父级编号:

1 One 1.1 Nested one 1.2 Nested two 2 Two 2.1 Nested one 2.2 Nested two 2.3 Nested three 3 Three

counter() 函数有两种形式: counter() 和 counter(, )。生成的文本是伪元素范围内指定名称的最内层计数器的值。

counters() 函数也同样有两种形式:counters(, ) 和 counters(, , )。生成的文本由在伪元素范围内所有指定名称的计数器的值组成。这些值从最外层到最内层,使用指定的字符串()分隔。

以上两个函数均可以使用指定的 来渲染其值(默认值为 decimal)。你也可以使用 list-style-type 属性其他可选的值,或自定义样式。

基础示例和计数器嵌套示例这两个示例分别展示了 counter() 和 counters() 的使用方法。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3