问题描述
我认为这样做会更快:
#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性能.哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!