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

后端 未结 1 791
长发绾君心
长发绾君心 2021-02-12 15:52

I\'d assume that this would be faster:

#dialog .videoContainer { width:100px; }

than:

.videoContainer { width:100px; }
<         


        
1条回答
  •  渐次进展
    2021-02-12 16:16

    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 讨论(0)
提交回复
热议问题