サンプル一覧
1段目/1からはじまる
2段目/0からはじまる
3段目/01からはじまる
4段目/001からはじまる
See the Pen CSS / counter-increment by 125naroom (@125naroom) on CodePen.
「1」からはじまる
See the Pen CSS / counter-increment by 125naroom (@125naroom) on CodePen.
HTMLとCSSはこちら
HTML
<div>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
</div>
CSS
/*=======
1 2 3 4 5 ...
=======*/
div section {
counter-increment: section;
}
div section:before {
content: counter(section);
}
「0」からはじまる
See the Pen 【CSS】counter-incrementを使って擬似要素をリスト化する(1からはじまる) by 125naroom (@125naroom) on CodePen.
HTMLとCSSはこちら
HTML
<div>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
</div>
CSS
/*=======
0 1 2 3 4 ...
=======*/
div section:nth-of-type(1) {
counter-reset: section;
}
div section:not(:nth-of-type(1)) {
counter-increment: section;
}
div section:before {
content: counter(section);
}
「01」からはじまる
See the Pen 【CSS】counter-incrementを使って擬似要素をリスト化する(0からはじまる) by 125naroom (@125naroom) on CodePen.
HTMLとCSSはこちら
HTML
<div>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
</div>
CSS
/*=======
01 02 03 04 05 ...
=======*/
div section {
counter-increment: section;
}
div section:before {
content: counter(section, decimal-leading-zero);
}
「001」からはじまる
See the Pen 【CSS】counter-incrementを使って擬似要素をリスト化する(01からはじまる) by 125naroom (@125naroom) on CodePen.
HTMLとCSSはこちら
HTML
<div>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>
</div>
CSS
/*=======
001 002 003 004 005 ...
=======*/
div section {
counter-increment: section;
}
div section:before {
content: '0' counter(section, decimal-leading-zero);
}
div section:nth-of-type(99) ~ section:before {
content: counter(section, decimal-leading-zero);
}