较长的CSS选择器不好吗? [英] Is having a long CSS selector bad?

查看:80
本文介绍了较长的CSS选择器不好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是类似

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

性能不好?如果是,如何,如果不是,为什么?

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

我在Google上搜索并阅读了很多帖子,包括Mozilla的帖子,却找不到任何提及将大量的类名用作选择器是不好的.

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.

推荐答案

不,这里没有性能问题.

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.

这篇关于较长的CSS选择器不好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆