开发者

CSS: #id .class VS .class performance. Which is better?

开发者 https://www.devze.com 2023-04-10 04:59 出处:网络
I\'d assume that this would be faster: #dialog .videoContainer { width:100px; } than: .videoContainer { width:100px; }

I'd assume that this would be faster:

#dialog .videoContainer { width:100px; }

than:

.videoContainer { width:100px; }

Of course disregarding that .videoContainer in the first example would only be sty开发者_如何学Pythonled under the #dialog tag.


CSS selectors are matched from right to left.

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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消