CSS selectors, tag + class vs class

Let's imagine a very simple case:

div.className{}

vs

.className{}

Which option is faster and why?

+4
source share
2 answers

.className{} Faster loading due to smaller css file size.

It is also faster when rendering a page because there is no need to look for elements div.

Google manual :

Avoid qualifying identifiers and class names with type selectors. If it is not necessary (for example, with auxiliary classes), do not use element names in combination with identifiers or classes.

Avoiding unnecessary ancestor selectors is useful for performance reasons .

+4
source

div.classname .classname , . , , , , .

ne CSS , , , , ( - ! important ).

.class , . , , ? , div.classname , .box, (div), (.class) (div.class).

, div.class div, , , div.

W3 , . CSS, .

, - , , , , CSS.

Follow Up

+1

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


All Articles