Why does the general-sibling combinator allow toggling pseudo-element's content, but not the adjacent-sibling?

后端 未结 2 1120
-上瘾入骨i
-上瘾入骨i 2020-11-29 07:55

In this question \"CSS3 Selector That Works like jQuery's .click()?\" I posted an answer using the :checked state of an input, of type=\"

2条回答
  •  孤独总比滥情好
    2020-11-29 08:34

    Bug Work Around

    Apparently, certain valid pseudo-classes chained together allows it to work.

    These work (see Fiddle #1, Fiddle #2, Fiddle #3):

    #switch:checked + nav:only-of-type + label::before
    #switch:checked + nav:nth-of-type(1) + label::before
    #switch:checked + nav:nth-child(2) + label::before
    

    This did not (see Fiddle #4):

    #switch:checked + nav:not([class]) + label::before
    

    I tried some other :not() combinations, none of which allowed it to work.

    ** Best choice **

    #switch:checked + nav:nth-child(n) + label::before
    

提交回复
热议问题