Can ordered list produce result that looks like 1.1, 1.2, 1.3 (instead of just 1, 2, 3, …) with css?

后端 未结 11 1004
广开言路
广开言路 2020-11-22 10:13

Can an ordered list produce results that looks like 1.1, 1.2, 1.3 (instead of just 1, 2, 3, ...) with CSS? So far, using list-style-type:decimal has produced on

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 10:42

    You can use counters to do so:

    The following style sheet numbers nested list items as "1", "1.1", "1.1.1", etc.

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

    Example

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

    See Nested counters and scope for more information.

提交回复
热议问题