购物车
登陆 / 注册
微信扫码登陆

推荐手册

counters()

counters()
重复插入计数器
前端控 前端控 更新时间:2019-03-21 14:52:30

counters()

语法:

counters() = [ counters(name, string) | counters(name, string, list-style-type) ]{1,}

说明:

重复插入计数器。

  • 在CSS2.1中counters()只能被使用在content属性上。
  • counters()类似于重复使用了counter(),来看个示例

HTML:

<ol class="test"><li>Node<ol><li>Node</li><li>Node</li></ol></li><li>Node</li><li>Node</li></ol>

counters():

ol {
	counter-reset: item;
}
li:before {
	counter-increment: item;
	content: counters(item, &quot;.&quot;);
}

counter():

.test2 {
	counter-reset: item;
}
.test2 li {
	counter-increment: item;
}
.test2 li:before {
	content: counter(item)&quot;.&quot;;
}
.test2 li li {
	counter-increment: subitem;
}
.test2 li li:before {
	content: counter(item)&quot;.&quot;counter(subitem);
}

从上述代码可以看出,counters()适合使用在需要继承的章节上,而counter()更适合用在独立的计数场景上。

兼容性:

浅绿 = 支持

红色 = 不支持

粉色 = 部分支持


IEFirefoxChromeSafariOperaiOS SafariAndroid BrowserAndroid Chrome
6.0-7.02.0+4.0+3.1+3.5+3.2+2.1+18.0+
8.0+


实例

<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8" />

<style>
ol {
	margin: 0;
	padding: 0 0 0 2em;
	list-style: none;
	counter-reset: item;
}
li:before {
	counter-increment: item;
	content: counters(item, ".");
	color: #f00;
}
</style>
</head>
<body>
<ol class="test">
	<li>Node
		<ol>
			<li>Node
				<ol>
					<li>Node</li>
					<li>Node</li>
					<li>Node</li>
				</ol>
			</li>
			<li>Node</li>
		</ol>
	</li>
	<li>Node</li>
	<li>Node</li>
</ol>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

效果图:

网站导航
标签地图
学习路径
视频教程
开发软件
旗下子站
php中文网
phpstudy
技术文章
文档工具
关于我们
企业合作
人才招聘
联系我们
讲师招募
QQ交流群
QQ官方交流群
微信公众号
微信公众号