How does the universal selector work?

* { font-weight: normal; }
#stockTicker { font: 12px Verdana; }
.corpName { font-weight: bold; }
.stockUp { color: red; }

<div id="section">
   NYS: <span class="corpName"><span class="stockUp">GE</span></span> +1.0 ...
</div>

Why does the universal selector get the last word here when .corpName comes later in styles and also has higher specificity?

JSFiddle here: http://jsfiddle.net/zackgao/2q9Wh/

+4
source share
3 answers

CSS indicates that the assigned property value comes from a cascading, inherited, or initial property value in this priority order ( CSS specification ).

Since it *applies to <span class="stockUp">during a cascade, the inherited value is not considered.

<span class="corpName"> , , corpName * .

+10

, CSS , . , * . , . font-weight: bold .corpName, * CSS spanUp span

0

, . * " html", " ". ( ids: id).

, body{font-weight: normal;}

0

Source: https://habr.com/ru/post/1532749/


All Articles