Select odd even child excluding the hidden child

后端 未结 9 1407
暖寄归人
暖寄归人 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条回答
  •  孤城傲影
    2020-12-01 23:55

    :nth-child() pseudo-class looks through the children tree of the parent to match the valid child (odd, even, etc), therefore when you combine it with :not(.hidden) it won't filter the elements properly.

    Alternatively, we could fake the effect by CSS gradient as follows:

    .hidden {display:none;}
    
    .wrap {
      line-height: 1.2em;
      
      background-color: orange; 
      background-image: linear-gradient(transparent 50%, green 50%);
      background-size: 100% 2.4em;
    }
    xx
    xx
    xx
    xx
    xx
    xx

提交回复
热议问题