CSS counter-reset on nested list

后端 未结 3 796
天命终不由人
天命终不由人 2020-12-10 04:09

I\'m struggling with counter-reset when ol is in div. Red list in the snippet numbering should be:

1, 2, 3

not:

3条回答
  •  感动是毒
    2020-12-10 04:52

    One way to work this around would be to add a class (since you cannot select an element based on what is its parent), and exclude it from initial selection with :not pseudo-class:

    HTML:

    1. BBD
    2. BBD
      1. BBD
      2. BBD
      3. BBD
    3. BBD
    1. BBD
    2. BBD
    3. BBD
    1. BBD
    2. BBD
    3. BBD

    CSS:

    ol:not(.x) {
        counter-reset: item;
        list-style: none;
    }
    ol:not(.x) li:before {
        counter-increment: item;
        content: counters(item, ".")" ";
    }   
    

    as per this JSFiddle

提交回复
热议问题