counter-reset:none | [<identifier> <integer>]
参数说明如下:counter-increment:none | [<identifier> <integer>]
参数说明如下:
counter(name)
counters(name, string, list-style-type)
<!DOCTYPE html> <html> <head> <style> body { counter-reset: chapter; } h5, h6 { margin: 5px 0 5px; } h5 { counter-reset: section; counter-increment: chapter; } h6 { counter-increment: section; } h5:before { content: "Chapter " counter(chapter) ". "; } h6:before { content: counter(chapter) "." counter(section) " "; } </style> </head> <body> <h5>程序设计语言</h5> <h6>HTML and CSS</h6> <h6>JavaScript</h6> <h6>PHP</h6> <h6>Java</h6> <h5>数据库管理系统</h5> <h6>MySQL</h6> <h6>MariaDB</h6> <h6>PostgreSQL</h6> <h6>Oracle</h6> </body> </html>运行结果如下图所示:
图:计数器
注意:在使用 CSS 计数器之前,必须使用 counter-reset 创建计数器。
<!DOCTYPE html> <html> <head> <style> ol { /* 为每个ol元素创建新的计数器实例 */ counter-reset: ol-list; list-style-type: none; } li:before { /* 只增加计数器的当前实例 */ counter-increment: ol-list; /* 为所有计数器实例增加以“.”分隔的值 */ content: counters(ol-list, ".") "、"; } </style> </head> <body> <ol> <li>item</li> <li>item <ol> <li>item</li> <li>item</li> <li>item <ol> <li>item</li> <li>item</li> </ol> </li> <li>item <ol> <li>item</li> <li>item</li> <li>item</li> </ol> </li> </ol> </li> <li>item</li> <li>item</li> </ol> </body> </html>运行结果如下图所示:
图:计数器嵌套
本文链接:http://task.lmcjl.com/news/5666.html