Is it possible to specify a starting number for an ordered list?

前端 未结 10 2229
梦毁少年i
梦毁少年i 2020-12-02 16:18

I have a ordered list where I would like the initial number to be 6. I found that this was supported (now deprecated) in HTML 4.01. In this specification they say that you c

10条回答
  •  温柔的废话
    2020-12-02 16:50

    With CSS it is a bit tricky to cover the case that there are nested list items, thus only the first list level gets the custom numbering that does not interupt with each new ordered list. I'm using CSS combinator '>' to define the possible paths to the list items that shall get a custom numbering. See https://www.w3schools.com/css/css_combinators.asp

    body {
      counter-reset: li_cnt;
    }
    /* discard auto generated numbers */
    ol {
      list-style-type: none;
    }
    /* all possible paths to the list item that shall have custom numbering */
    section#TheContent > ol > li:before,
    body > ol > li:before {
      counter-increment: li_cnt;
      content: counter(li_cnt)'. '; /* add own numbers */
    }
    /* switch on default auto generated numbers for nested list items */
    li > ol {
      list-style-type: decimal;
    }
    
    
    
    
    

    Ordered Lists - numbering not interupted

    This example avoids for the first list level that each ordered list starts with 1:

    1st list:

    1. list item 1
    2. list item 2
    3. list item 3

    2nd list:

    1. item
    2. item
      1. item
      2. item
      3. item
    3. item

提交回复
热议问题