1

How come the universal selector (*) overrides the Firefox browser's default styles for the :link and :any-link:active pseudo-class selectors, though it has a specificity of 0?

*{color: red} beats :any-link:active{color:activetext}and :link{color: linktext} set by Firefox.

It's the same with Chrome by the way.

Chris Albert
  • 2,462
  • 8
  • 27
  • 31
p.cmnznd
  • 11
  • 1

3 Answers3

1

The browser default styles are of the user-agent origin which is always lower in precedence than author origin styles, regardless of specificity (notwithstanding !important, which upends this order).

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

The Universal Selector is a simple selector and is usually set as a "last resort"/ fallback for CSS compilers.

With testing, on Firefox, I DO NOT SEE in my own codes and example below that * beats either of the pseudo-classes you reference.

:any-link {
  color: brown;
  font-weight:bold;
}

* {
  color: blue;
}
<body>
<div>horses and trees <a href='https://webzoom.freewebs.com/schazaars/11612%20indian%20horses%20052.JPG'>whoopieee!</a></div>
</body>

See the example above shows that the anchor is a different colour from the rest of the text, which is expressedly opposite to what you claim, that the * element overrides the pseudo-class.

Also note that cascade doesn't effect this; it's to do with the specificity of the elements themselves.

Martin
  • 22,212
  • 11
  • 70
  • 132
  • 2
    _"With testing, on Firefox, I DO NOT SEE in my own codes and example below that * beats either of the pseudo-classes you reference."_ - not in this scenario, where both rules have the same origin. But if the `:any-link` comes from the user agent stylesheet, things are different. (https://bitsofco.de/the-effect-of-importance-and-origin-on-specificity/) – CBroe Jun 01 '22 at 14:02
-1

you can use

@-moz-document url-prefix() {
 a {
     color: red;
   }
}

as firefox has its own set of default CSS in the browser.

Umair
  • 1
  • 1
  • OP states this issue occurs on other browsers as well, so it's not a Firefox specific issue. Also on my firefox this issue does not appear, so it doesn't even seem to be a browser issue at all. – Martin Jun 01 '22 at 15:45