I cannot understand the reason, but checking in chrome, it seems like using the :not selector is not working with a tag. Does anyone understand the reason?
Here is an example codepen: https://codepen.io/anon/pen/PQezVB
:not(a){
color:blue;
}
I cannot understand the reason, but checking in chrome, it seems like using the :not selector is not working with a tag. Does anyone understand the reason?
Here is an example codepen: https://codepen.io/anon/pen/PQezVB
:not(a){
color:blue;
}
Found a solution, it should be used like this:
p {
color: initial;
}
:not(p) {
color: green;
}
The :not(selector) selector matches every element that is NOT the specified element/selector. The :not() CSS pseudo-class represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the negation pseudo-class.
So to use it you should specify the css of the element that is then use not
for those how don't
*:not(a){
color:blue;
}
* {
color:black;
}
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</span>
<i>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</i>
<h1>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</h1>
<a>This is the link "a tag"</a>
Found the solution here: Is the CSS :not() selector supposed to work with distant descendants?
Basically by selecting everything but the element you also select its parent elements and hence it's colored as well from inheritance.
:not(a) { color: red; }
in this case is almost equivalent to:
* { color: red; } /* includes "body" element etc. */
a { color: inherit; }
Adding "href" attribute to the anchor tag seems to solve this issue.
<p>Hello world</p>
<a href="">Some link</a>