css定位方法会影响浏览器渲染性能吗?
考虑两个DIV A和B,其中A包含B,还有CSS:
A { margin-left: -2000px; }
B { margin-left: 2000px; }
有了这个CSS,B的位置与没有CSS的情况没有区别,我想知道渲染时性能会下降吗?与没有 CSS 的情况进行比较。
Considerring two DIVs A and B, which A includes B, and CSS:
A { margin-left: -2000px; }
B { margin-left: 2000px; }
with this CSS, position of B is no difference to its situation with no CSS, i want to know will there be a performance decrease when rendering? Compare to the case of no CSS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在让浏览器执行不必要的 CSS 计算,因此它的性能会稍微降低一点。 :)
没有用户可能会注意到它!
为了实现与编码处理器的相似性,在以这种方式声明变量时需要更少的时间:
而不是这样做:
但我相信没有人(从用户的角度来看)会感觉到差异,除了编码员,他们会认为你是一个有线人格,当他们在你的代码中读取此类内容。
You are making the browser do uneccesary CSS calculation, so it will be a really tiny infinitesimal bit less performant. :)
No user will probably ever notice it!
To do a similarity with coding a processor take less when declaring a variable in this way:
rather than doing:
but I believe nobody (from a user stand point) will ever feel the difference except coders that would think at you as a wired personality when they read in your code such kind of stuff.
并不真地。如果有的话,你所说的就是 0.01 秒的时间。
如果您对同一元素应用了冲突的设置,则将使用最后一个设置。
Not really. If there was, you would be talking 0.01 of a seconds' worth.
If you applied conflicting settings to the same element, the last setting will be used.
考虑到大多数连接的速度,您可能不必担心太多。除非您使用的样式表有数千行,否则最好将其通过压缩工具 ,但除此之外,我不会太担心。
Considering the speed of most connections, you've probably not got much to worry about. Unless you're using a Stylesheet that has thousands of lines, might be good to put it through a Compression tool, but other than that, I wouldn't worry too much about it.
我注意到性能下降的唯一情况是具有
position:fixed
的元素(当您滚动时,它们会保持在同一位置)...当您滚动时,Firefox 会变得(非常轻微)不稳定。页。The only situation when I noticed a performance decrease is with elements that have
position:fixed
(they stick to the same position while you scroll)... Firefox becomes (ever so slightly) choppy when you scroll the page.