css3 :not() selector to test parent's class

前端 未结 1 1834
轻奢々
轻奢々 2021-01-03 17:20

I have an unordered list, using bootstraps \"tabs\" plugin. The code looks like this:

相关标签:
1条回答
  • 2021-01-03 18:09

    Combinators such as >, + and space for descendant aren't allowed within :not() in CSS; they're only allowed as a jQuery selector. You can find out more in this other question.

    That said, you may be able to use :not() on the li alone, and move out the > a part; however this will depend on the structure of your ul and li elements:

    li:not(.active) > a {
        color: grey;
    }
    

    For example, you can always chain other selectors, such as .span3 if you want to limit it to a elements with li parents of that class only:

    li.span3:not(.active) > a {
        color: grey;
    }
    

    Keep in mind, though, that you can only rely on using :not() in this manner if you have control over the markup or the structure is at least predictable (e.g. you know what kind of elements the parents are). In your case for example, you're only looking at li.span3 > a, and applying styles only when the li.span3 does not have the active class. With this information you can construct a selector like one of the above, which should work as expected.

    0 讨论(0)
提交回复
热议问题