Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is having a long CSS selector bad?

Tags:

css

Is a selector like

.a, .b, .c, .d, .e, .f, .g, .h, ......... , .zzzzz {font-size:16px}

bad for performance? If yes how and if no why?

I Googled and read a lot of posts including the ones by Mozilla and couldn't find any mention of having a large number of class names as a selector being bad.

like image 453
Nitin Avatar asked Jan 25 '13 09:01

Nitin


2 Answers

No, there is no performance problem here.

What is bad is a long selector involving many checks but your selector is in fact a sequence of selectors, equivalent to

 .a {font-size:16px}
 .b {font-size:16px}
  ...

Selectors with just a class are among the most efficient ones.

There's no real problem, even if you probably should have less classes in order to manage your code more easily.

like image 64
Denys Séguret Avatar answered Nov 16 '22 00:11

Denys Séguret


This is the valid syntax for assigning a common properties to multiple classes at a time. there is no down side effect.

like image 2
naresh kumar Avatar answered Nov 16 '22 00:11

naresh kumar