Creating table of contents in html

前端 未结 4 1517
囚心锁ツ
囚心锁ツ 2021-02-05 11:49

Is it possible to create an ordered list like the following? I like this for a table of contents I\'m creating.

  1. Into
  2. Section1
    2.1 SubSection1
    2.
4条回答
  •  囚心锁ツ
    2021-02-05 12:08

    This can indeed be done with pure CSS:

    ol {
        counter-reset: item
    }
    li {
        display: block
    }
    li:before {
        content: counters(item, ".")" ";
        counter-increment: item
    }
    

    Same example as a fiddle: http://jsfiddle.net/N79nP/

提交回复
热议问题