CSS counter-reset 屬性
定義和用法
counter-reset 屬性設(shè)置某個選擇器出現(xiàn)次數(shù)的計數(shù)器的值。默認(rèn)為 0。
利用這個屬性,計數(shù)器可以設(shè)置或重置為任何值,可以是正值或負(fù)值。如果沒有提供 number,則默認(rèn)為 0。
注釋:如果使用 "display: none",則無法重置計數(shù)器。如果使用 "visibility: hidden",則可以重置計數(shù)器。
| 默認(rèn)值: | none |
|---|---|
| 繼承性: | no |
| 版本: | CSS2 |
| JavaScript 語法: | object.style.counterReset="subsection" |
實例
對部分和子部分進(jìn)行編號(比如 "Section 1"、"1.1"、"1.2")的方法:
body
{
counter-reset:section;
}
h1
{
counter-reset:subsection;
}
h1:before
{
content:"Section " counter(section) ". ";
counter-increment:section;
}
h2:before
{
counter-increment:subsection;
content:counter(section) "." counter(subsection) " ";
}
瀏覽器支持
所有瀏覽器都支持 counter-reset 屬性。
注釋:如果已規(guī)定 !DOCTYPE,那么 Internet Explorer 8 (以及更高版本)支持 counter-reset 屬性。
可能的值
| 值 | 描述 |
|---|---|
| none | 默認(rèn)。不能對選擇器的計數(shù)器進(jìn)行重置。 |
| id number |
id 定義重置計數(shù)器的選擇器、id 或 class。 number 可設(shè)置此選擇器出現(xiàn)次數(shù)的計數(shù)器的值。可以是正數(shù)、零或負(fù)數(shù)。 |
| inherit | 規(guī)定應(yīng)該從父元素繼承 counter-reset 屬性的值。 |
相關(guān)頁面
CSS 參考手冊:CSS :before 偽元素
CSS 參考手冊:CSS :after 偽元素
CSS 參考手冊:content 屬性
CSS 參考手冊:counter-increment 屬性