If the identifiers in HTML must be unique, why sometimes I see in Css something like div # nav-blue?

Since the identifier must be unique in HTML, why sometimes I see in Css selectors formatted as (div # nav-blue), since it is obvious that there will be no other element that has this identifier for this div, so aint writting # nav -blue makes more sense?

+7
html css css-selectors
source share
1 answer

This will not change or a little.

You can do this for some reason: more visibility when saving code. It is easier to find and remember a style for each type of element.

The second reason is the selector priority.

There are several different priorities:

!important > #id > .class > element 

you can assume that

  element = 1 .class = 10 #id = 100 !important= 1000 

And then div#id = 101> #id = 100

 div#myid{ color:red; } #myid{ color:blue; } .myclass{ color:yellow; } div{ color:green; } 
 <div class="myclass" id="myid"> Some text </div> 
+5
source share

All Articles