Creating table of contents in html

前端 未结 4 1536
囚心锁ツ
囚心锁ツ 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:19

    This code leads to the desired output for me:

    1. foo
    2. bar
      1. baz
      2. qux
    3. alpha
      1. beta
      2. gamma

    CSS:

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

    Fiddle: http://jsfiddle.net/Lepetere/evm8wyj5/1/

提交回复
热议问题