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

后端 未结 11 1081
广开言路
广开言路 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 11:06

    In the near future you may be able to use the ::marker psuedo-element to achieve the same result as other solutions in just one line of code.

    Remember to check the Browser Compatibility Table as this is still an experimental technology. At the moment of writing only Firefox and Firefox for Android, starting from version 68, support this.

    Here is a snippet that will render correctly if tried in a compatible browser:

    ::marker { content: counters(list-item,'.') ':' }
    li { padding-left: 0.5em }
    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

    You may also want to check out this great article by smashingmagazine on the topic.

提交回复
热议问题