, it would be be...">

Best practice for calling classes in CSS

If you have an HTML page with a class in an element, for example <div class="myClass">, it would be best to link to it in CSS like .myClassor div.myClass?

+3
source share
4 answers

div.myClassmakes style declarations more specific. In other words, it has a higher priority. Therefore, it is sometimes useful to specify it in order to avoid CSS conflicts when you have many developers on board a project and people add classes like no tomorrow. In other words, if you added Bob:

.myClass {
  color: red;
}

and Sarah adds:

div.myClass {
  color: blue;
}

The Sarah class will surpass the Bob class if you have:

<div class="myClass">Sarah FTW</div>

, , .:)

+9

- (-div) "myClass" - -, .myClass.

, .error color:red, div.error background:red, .error, div.error.

+4

, , , - div.myClass, div. 2 :

  • .myClass, a.myClass, .myClass myClass, .
  • CSS . , - , , , myClass divs, HTML-, , .
+2

div.myClass , .myClass. , , . , , , ID , .

CSS - , - , , CSS - .

+1

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


All Articles