the universal selector

the universal selector completely bypasses the inheritance mechanism. By writing a rule that's matched by all elements, you have a rule that explicitly assigns a given style (or collection of styles) to every element. Consider:

* {color: cyan;} 

Given this rule, no element can possibly inherit the color of its parent, because the above example explicitly sets the color of every element to cyan. Hyperlinks, for example, will be cyan along with everything else.

Consider that you can restrict the universal selector's effects to a given context. Perhaps you'd like every element that's a descendant of DIV with a class of dangerto be red. This would be written:

DIV.danger * {color: red;} 

At first glance, this seems no different than if the * were left out, but that's not quite true. Again we see that there's a difference: The rule shown would match every DIV descendant, and therefore override the inheritance mechanism.

https://meyerweb.com/eric/articles/webrev/200006a.html

https://softwareengineering.stackexchange.com/a/178072

评论

© ID4333709 | Powered by LOFTER