问题描述
对于这个问题,我只是比较浏览器在两个元素上呈现CSS的速度,这些元素的不同之处仅在于一个元素具有一个类,一个元素具有一个id.
For this question, I'm only comparing a browser's speed in rendering the CSS on 2 elements which are different only in that one has a class and one has an id.
(这与JS标识,锚点使用等无关)
(This has nothing to do with JS identification, anchor use, etc.)
<div class="myclass">classed element</div>
<div id="myid">ided element</div>
有人对此有数字吗?我已经读过CSS id可以更快",但是要多少呢?我要冒险猜测它可以忽略不计,但是知道这将很有趣.
Does anyone have numbers on this? I have read that CSS ids are 'faster,' but by how much? I'm going to hazard a guess that it's negligible, but it would be interesting to know.
推荐答案
ID的 在某些情况下更快,但并非全部
ID's are faster in some cases, but not all
这里还针对您的电话号码请求进行了性能测试: http://oli.jp/2011/ids/#table1
There's also a performance test here for your numbers request: http://oli.jp/2011/ids/#table1
结论
正确使用ID的速度更快,但与类之间的差异却很小-无需任何考虑.
ID's used correctly are faster, but with such a minimal difference vs classes - it's not worth any consideration.
这篇关于CSS类和id之间的处理速度差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!