0

I used the #footer a selector before, but after removing #footer to make the change apply to all <a>'s on the page except the ones in a div with a class of .navbar, no links get the following selectors assigned: a:not(.navbar a),a:not(.navbar a):hover, a:not(.navbar a):active (also seen in Google Chrome element inspector)

I created 2 snippets to represent what I'm trying to say:

  1. Working example of first version

a {
  text-decoration: none !important;
  color: #3D64FF
}

#footer a {
  text-shadow: none;
  padding: 0;
  transition: text-shadow 0.1s linear, padding 0.1s linear;
}

#footer a:hover {
  text-shadow: 0px 0px 5px #3D64FF;
  padding: 0 5px;
  transition: text-shadow 0.1s linear, padding 0.1s linear;
}

#footer a:active {
  text-shadow: 0px 0px 7px #3556DB;
  padding: 0 2px;
  transition: text-shadow 0.1s linear, padding 0.1s linear;
}
<div id="footer">
  <a href="#">Footer link #1</a><br>
  <a href="#">Footer link #2</a><br>
  <a href="#">Footer link #3</a><br>
  <a href="#">Footer link #4</a>
</div>
  1. Broken, new code

a {
  text-decoration: none !important;
  color: #3D64FF
}

a:not(.navbar a) {
  text-shadow: none;
  padding: 0;
  transition: text-shadow 0.1s linear, padding 0.1s linear;
}

a:not(.navbar a):hover {
  text-shadow: 0px 0px 5px #3D64FF;
  padding: 0 5px;
  transition: text-shadow 0.1s linear, padding 0.1s linear;
}

a:not(.navbar a):active {
  text-shadow: 0px 0px 7px #3556DB;
  padding: 0 2px;
  transition: text-shadow 0.1s linear, padding 0.1s linear;
}
<div calss="navbar"><a href="#">NAVBAR link</a></div>
<a href="#">Not NAVBAR link</a>

I have to fix it again, so it applies to the entire page, except that one div.

SeinopSys
  • 8,787
  • 10
  • 62
  • 110

1 Answers1

3

You cannot do a:not(.navbar a) in CSS.

If you know your a will always be directly nested within .navbar and you want to exclude that a, you could select :not(.navbar) > a instead. But if the nesting level is arbitrary and you want to exclude a nested anywhere within .navbar, then you'll probably have trouble writing a CSS selector for that. Something like :not(.navbar) a can always match some other element higher up in the tree. See this answer for another example of why it won't work.

The simplest solution to this is to apply the effects to all a elements, then undo them in .navbar a:

.navbar a {
  text-shadow:none;
  padding:0;
  -webkit-transition-property: none;
  -moz-transition-property: none;
  -o-transition-property: none;
  transition-property: none;
}

jsFiddle preview

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356