Select odd even child excluding the hidden child

后端 未结 9 1395
暖寄归人
暖寄归人 2020-12-01 23:30

Line 3 is a hidden

. I don\'t want that one to be taken from the odd/even css rule.

What is the best approach to get t

9条回答
  •  萌比男神i
    2020-12-01 23:59

    Here's a CSS-only solution:

    .box {
      background: orange;
    }
    
    .box:nth-child(even) {
      background: green;
    }
    
    .box.hidden {
      display: none;
    }
    
    .box.hidden ~ .box:nth-child(odd) {
      background: green;
    }
    
    .box.hidden ~ .box:nth-child(even) {
      background: orange;
    }
    xx
    xx
    xx
    xx
    xx
    xx

提交回复
热议问题