125naroom / デザインするところ(会社)です。

【CSS】counter-incrementを使って擬似要素をリスト化する

【CSS】counter-incrementを使って擬似要素をリスト化する

ワードプレスのランキング表示で役立ったメモ。
擬似要素でリスト化する。

サンプル

1段目/1からはじまる
2段目/0からはじまる
3段目/01からはじまる
4段目/001からはじまる

See the Pen
CSS / counter-increment
by 125naroom (@125naroom)
on CodePen.

CSS

1からはじまる

div section {
  counter-increment: section;
}
div section:before {
  content: counter(section);
}

0からはじまる

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からはじまる

div section {
  counter-increment: section;
}
div section:before {
  content: counter(section, decimal-leading-zero);
}

001からはじまる

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);
}

おすすめ

Googleさんのおすすめ

Googleさんのおすすめ

デザインの記事

センダイパルコ15th | 仙台PARCO
ちょっと思い出しただけ
【Google Chrome】ショートカットキーまとめ(Windows or Mac)