CSS:#id .class VS .class性能.哪个更好? [英] CSS: #id .class VS .class performance. Which is better?

查看:118
本文介绍了CSS:#id .class VS .class性能.哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这样做会更快:

#dialog .videoContainer { width:100px; }

大于:

.videoContainer { width:100px; }

当然,第一个示例中的.videoContainer只会在#dialog标记下设置样式.

Of course disregarding that .videoContainer in the first example would only be styled under the #dialog tag.

推荐答案

CSS选择器是因此,.videoContainer应该比#dialog .videoContainer更快",因为它错过了对#dialog的测试.

Therefore, .videoContainer should be "faster" than #dialog .videoContainer because it misses out testing for #dialog.

但是,这些充其量都是无关紧要的-您永远不会注意到它们之间的区别.对于正常大小的页面,我们谈论的时间太少了,甚至根本不存在.

However, this is all irrelevant at best - you'll never notice the difference. For normally sized pages, the amount of time we're talking about is so insignificant as to be nonexistent.

以下是专家的相关答案,您应该阅读:为什么浏览器从右到左匹配CSS选择器?

Here's a relevant answer by an expert that you should read: Why do browsers match CSS selectors from right to left?

这篇关于CSS:#id .class VS .class性能.哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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