CSSの疑似要素に連番を自動生成

最終更新日

SCSSの @for ループを使用することで、1から100までの :nth-of-type と content の指定を一括で自動生成できます。

See the Pen CSSの疑似要素に連番を自動生成 by nerdspec (@nerdspec) on CodePen.

SCSS

// 1から100までループ処理
@for $i from 1 through 100 {
  li:nth-of-type(#{$i})::before {
    content: "#{$i}";
  }
}