返回到:CSS 计数器 | CSS教程
属性定义及使用说明
counter-reset属性创建或重置一个或多个计数器。
counter-reset属性通常是和counter-increment属性,content属性一起使用。
| 默认值: | none |
|---|---|
| 继承: | no |
| 版本: | CSS2 |
| JavaScript 语法: | object.style.counterReset=”subsection” |
所有主流浏览器都支持counter-reset属性。
注意: IE8只有指定!DOCTYPE才支持counter-reset属性。
属性值
| 值 | 说明 |
|---|---|
| none | 默认。不能对选择器的计数器进行重置 |
| id number | id 定义重置计数器的选择器、id 或 class。 number 可设置此选择器出现次数的计数器的值。可以是正数、零或负数。 |
| inherit | 规定应该从父元素继承 counter-reset 属性的值 |
实例
对部分和子部分进行编号(比如 “Section 1″、”1.1″、”1.2″)的方法:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程网(web176.com)</title>
<style>
body {counter-reset:section;}
h1 {counter-reset:subsection;}
h1:before
{
counter-increment:section;
content:"Section " counter(section) ". ";
}
h2:before
{
counter-increment:subsection;
content:counter(section) "." counter(subsection) " ";
}
</style>
</head>
<body>
<p><b>注意:</b> 仅当 !DOCTYPE已经定义 IE8支持 这个属性.</p>
<h1>HTML tutorials</h1>
<h2>HTML Tutorial</h2>
<h2>XHTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h1>Scripting tutorials</h1>
<h2>JavaScript</h2>
<h2>VBScript</h2>
<h1>XML tutorials</h1>
<h2>XML</h2>
<h2>XSL</h2>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/cssprop/5259.html
支付宝
微信