Why does #box2 a
overrides #box a
and when I put .box2 a
it doesn't override?
#box a { font-size:25px; }
#box2 a { font-size:55px; }
<div id="box">
<a href="">link</a>
<div id="box2"><a href="">link</a></div>
</div>
Why does #box2 a
overrides #box a
and when I put .box2 a
it doesn't override?
#box a { font-size:25px; }
#box2 a { font-size:55px; }
<div id="box">
<a href="">link</a>
<div id="box2"><a href="">link</a></div>
</div>
CSS rules always occur in order of appearance, so if two apply to a specific element, the one appearing last would have precedence.
Also, as mentioned, if you use .box2
that would apply to an element with the class name box2
, whereas #box2
would apply to an element with an id of box2
Understanding CSS Style Precedence
Another Stack Overflow question relating to CSS classes and ids, and precedence
Because you may did not add a class="box2"
. The .
refers to classes. #
is for id.