Is there a reason for including the tag name in the CSS or class selector?

I am wondering if there is a difference between div.classand .classhow CSS selectors, if there is only one tag (DIV) with this attribute. Same for identifiers: div#IDand #ID.

Any idea that, anyway, is there a difference? For me, I use a class or identifier in these situations; but only because he is gaining faster.

+1
source share
5 answers
  • They are more specific, so long ones will override the shorter version if they conflict. div.foowill have a specificity of 11, and .foohas a specificity of 10.
  • , , nodename, node, , , , / .
+5

.

p#id is (0,1,0,1)

#id is (0,1,0,0)

, , , .

, .

+1

, , , CSS , HTML- .

, , , - , HTML.

, , .

0

, CSS . - - differenciate p.error div.error, . , , HTML - , .

0

, , DIV .

-1
source

All Articles