能,需配合counter-reset和counter-increment;单靠content静态值无法动态递增;多级序号用多组计数器及counter()第二参数指定格式(如decimal、lower-roman);但不可替代
- ,因可访问性差、打印异常且旧浏览器兼容问题多。
伪元素
::before::aftercounter-incrementcounter-resetcontent: "1. "content: "第" counter(item) "项"counter-reset: itemcounter-increment: itemcounter()contentcounter()counter(section)counter(subsection)counter-increment: subsectioncounter-reset: subsectioncounter-resetliol > li > ol > liolliol { counter-reset: section; }
ol > li { counter-increment: section; }
ol > li::before { content: counter(section) ". "; }
ol ol { counter-reset: subsection; }
ol ol > li { counter-increment: subsection; }
ol ol > li::before { content: counter(section) "." counter(subsection) " "; }counter()decimallower-romanupper-alphalower-greeklist-style-typecounter(section, lower-roman)decimalcounter(section, "一")contentdecimallower-romanupper-alpha"第" counter(x) "条"
::beforecounter()counter(a) "." counter(b)content
floatgrid