How can I make it happen that the :not()-selector works in the following example?
HTML
<div id="content">
  <div id="one">
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
</div>
  <div id="two">
    <div class="mystyle"><p>This is a <a href="">link</a>.</p></div> <!-- should NOT be green -->
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
</div>
</div>
CSS
#content a:not(.mystyle) {
  color: green;
}
JSFIDDLE
Link to jsfiddle
Important
I am trying to style an external widget on my blog. I don't have access to it's HTML so changing the HTML is not an option. I am looking for an CSS-only solution.
In your example, the :not() selector is applied to the a element. This would only select a tags that did not have a .mystyle class on it.
#content > * > *:not(.mystyle) a {
    color: green;
}
The above will select any descendants 2 levels down that don't have a .mystyle class, then colour all their decendant a tags green.
Below is a working example:
#content > div > div:not(.mystyle) a {
  color: green;
}
<div id="content">
  <div id="one">
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
</div>
  <div id="two">
    <div class="mystyle"><p>This is a <a href="">link</a>.</p></div> <!-- should NOT be green -->
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
</div>
</div>
There are four links. All links should be green with one exception: the link in the class="mystyle".
Then why are you using :not()? Just give the color to the existing class.
* { color: green; }
.mystyle * { color: red; }
<div id="content">
  <div id="one">
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
</div>
  <div id="two">
    <div class="mystyle"><p>This is a <a href="">link</a>.</p></div> <!-- should NOT be green -->
    <div><p>This is a <a href="">link</a>.</p></div> <!-- should be green -->
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With