0

would anyone be so kind to tell me what's wrong with the following CSS selector?

:not(ul[class="nav navbar-nav"] li) > a  

I'm trying to select all anchor elements whose parent is not ul[class="nav navbar-nav"] li Thx in advanced :)

I'm trying to set a CSS property for all anchors except the following ones:

<ul class="nav navbar-nav">
  <li class="active">
    <a href="#">Hi</a>
  </li>
  <li>
    <a href="#">Hello</a>
  </li>
  <li>
    <a href="#">Bye</a>
  </li>
</ul>

Edit: The right selector using jQuery would be jQuery(':not(ul[class="nav navbar-nav"] li) > a')

peris
  • 943
  • 3
  • 20
  • 33
  • "The right selector using jQuery would be" the exact same selector, just, you know, with jQuery. – BoltClock Apr 04 '17 at 18:51
  • @Vucko: But the question here isn't about multiple arguments to :not(). It's about a single, complex selector argument to :not(). – BoltClock Apr 04 '17 at 18:52

1 Answers1

1

You're better off styling the general first, and then overriding with the specific. Would this suffice:

a {color: red}

ul.nav.navbar-nav > li > a  {
  color:blue;
}
<ul class="nav navbar-nav">
  <li class="active">
    <a href="#">Hi</a>
  </li>
  <li>
    <a href="#">Hello</a>
  </li>
  <li>
    <a href="#">Bye</a>
  </li>
</ul>
<a href="#">Default Link Style</a>
nvioli
  • 4,137
  • 3
  • 22
  • 38
  • Yeah, there is no good alternative, really. – BoltClock Apr 04 '17 at 19:07
  • By now, i did something similar to @nvioli proposal but i was wondering about how to accomplish what asked in the post. Thx anyway :) – peris Apr 04 '17 at 19:31
  • @user846226 in css you cannot select by parent, so your requirement to select elements whose "`parent is not xxx`" is unfortunately impossible, quite apart from the issue with the `not` selector. – nvioli Apr 04 '17 at 20:02
  • @nvioli, i disagree. you could use ":not(ul) > a" to select anchors whose parents are not ul elements. – peris Apr 04 '17 at 20:11