counter-increment CSS屬性增加一個(gè)或多個(gè)計(jì)數(shù)器的值。此屬性對(duì)于創(chuàng)建自動(dòng)編號(hào)功能非常有用。
下表為此屬性的用法說(shuō)明和版本歷史記錄,以及該屬性在javascript腳本中的使用語(yǔ)法。
默認(rèn)值: | none |
---|---|
適用于: | 所有元素 |
繼承: | 沒(méi)有 |
可動(dòng)畫(huà)制作: | 否。請(qǐng)參見(jiàn) 動(dòng)畫(huà)屬性。 |
版本: | CSS 2、3 |
JavaScript 語(yǔ)法: | object.style.counterIncrement="section" |
該屬性的語(yǔ)法如下:
counter-increment: [ identifier integer ]1 or more pairs | none | initial | inherit
下面的示例演示了如何使用counter-increment屬性。
body { counter-reset: section; } h1 { counter-reset: category; } h1:before { counter-increment: section; content: "Section " counter(section) ". "; } h2:before { counter-increment: category; content: counter(section) "." counter(category) " "; }測(cè)試看看?/?
下表描述了此屬性的值。
值 | 描述 |
---|---|
identifier | 要遞增的計(jì)數(shù)器名稱(chēng)。 |
integer | 要添加到計(jì)數(shù)器的值。默認(rèn)增量為1。允許零或負(fù)值。 |
none | 沒(méi)有計(jì)數(shù)器將增加。這是默認(rèn)值。 |
initial | 將此屬性設(shè)置為其默認(rèn)值。 |
inherit | 如果指定,則關(guān)聯(lián)元素采用其父元素direction的屬性值。 |
counter-increment屬性瀏覽器的兼容性,下表中的數(shù)字表示支持該屬性的瀏覽器最低版本號(hào);所有主流瀏覽器均支持該屬性。
![]() |
|
警告: Internet Explorer 7和更早版本不支持該counter-increment屬性。IE8僅在<!DOCTYPE>指定有效值的情況下才支持。
請(qǐng)參考以下教程:CSS偽元素。
相關(guān)屬性:content,counter-reset。