(这与Js识别,锚点使用等无关)
<div >classed element</div><div ID="myID">IDed element</div>
有没有人有这个数字?我已经读过CSS ID’更快’,但是多少钱?我会冒险猜测它可以忽略不计,但知道它会很有趣.
解决方法 http://oli.jp/2011/ids/ID在某些情况下更快,但不是全部
It’s a common belIEf that ID selectors are the fastest,but this comes with a big caveat: IDs are fastest CSS selector only if they’re the key selector. What’s that? Well,while you probably read selectors from left to right,browsers read them from right to left.
这里还有一个针对您的号码请求的性能测试:http://oli.jp/2011/ids/#table1
结论
ID的正确使用速度更快,但与类相比差别很小 – 不值得考虑.
总结It seems to me that there are no convincing reasons to use IDs in selectors for CSS styling¹,as CSS classes can do everything IDs can. Hopefully you’ll agree there are some good reasons not to. Think about it the next time you start a personal project or redesign your own site,and try adding a class (or ARIA landmark roles) for styling instead. Save IDs for fragment IDentifIErs or JavaScript hooks
以上是内存溢出为你收集整理的html – 处理CSS类和id之间的速度差异全部内容,希望文章能够帮你解决html – 处理CSS类和id之间的速度差异所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)