目录

counter-increment

描述 (Description)

counter-increment属性设置计数器在每次出现选择器时递增的程度。 默认增量为1。

可能的值 (Possible Values)

  • name - 计数器的名称。 名称可以是任何字符串值。

  • integer - 每次元素出现在文档中时定义指定计数器的增量。 此增量可以为零,甚至为负。 如果未提供整数,则计数器加1。

  • none - 不执行增量。

适用于 (Applies to)

所有HTML元素。

DOM语法 (DOM Syntax)

object.style.counterIncrement = "chapter 2";

例子 (Example)

此示例显示了使用“第1章”,“1.1”,“1.2”等对章节进行编号的方法。

<html>
   <head>
      <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>
      <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>
   </body>
</html> 

它会产生以下结果 -

新页面打开
↑回到顶部↑
WIKI教程 @2018