Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the universal selector working here?

* { 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 universal selector get the last say here when .corpName comes later in the styles and also has higher specificity?

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

like image 710
Zack Gao Avatar asked Dec 25 '22 11:12

Zack Gao


1 Answers

CSS specifies that the assigned value of a property comes from the cascade, inherited, or the property's initial value, in that priority order (CSS spec).

Since * is applied to the <span class="stockUp"> during the cascade the inherited value isn't considered.

Text directly inside the <span class="corpName"> element would be styled as you'd expect since the corpName class would beat out the * during the cascade.

like image 136
mrmcgreg Avatar answered Dec 29 '22 10:12

mrmcgreg