是重要的性能坏吗? [英] Is !important bad for performance?

查看:65
本文介绍了是重要的性能坏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我讨厌他们,它违反CSS的级联性质,如果你不小心使用它们,你最终会添加更多的!重要循环。

I hate them, it defies the cascading nature of CSS, and if you don't use them with care you end up in a loop of adding more !important.

但我想知道它们对性能有害吗?

But I want to know are they bad for performance?

EDIT br>
从(快)的回复我可以得出结论,它不会有(显着)的影响性能。
但是很高兴知道,即使它只是一个额外的论据,以阻止他人。)

EDIT
From the (fast) replies I can conclude it won't have a (significant) impact on performance. But it's nice to know, even if it's just as an extra argument for discouraging others ;).

EDIT 2 >
BoltClock指出,如果有两个!important 声明,规格说它会选择最具体的一个。

EDIT 2
BoltClock pointed out that if there are 2 !important declarations the specs says it will pick the most specific one.

推荐答案

我不认为!important 本身就不利于浏览器匹配规则的速度不构成选择器的一部分,只是声明的一部分)

I don't think that !important is inherently bad in terms of how quickly the browser matches rules (it does not form part of the selector, only part of the declaration)

然而,如前所述,它会降低代码的可维护性,因此可能导致它由于未来的变化而在尺寸上不必要地增长。 !important 的用法也可能会降低开发人员的效果。

However, as has already been stated, it will reduce the maintainability of your code, and thus likely cause it to grow unnecessarily in size due to future changes. The usage of !important would also likely reduce developer performance.

strong> picky,你还可以说!important 为你的CSS文件添加了11个额外的字节,这不是真的很多,但我想如果你有一个公平的少数!important 在你的样式表中它可以加起来。

If you were being really picky, you could also say that !important adds 11 extra bytes to your CSS file, this isn't really much, but I guess if you have a fair few !importants in your stylesheet it could add up.

只是我的想法,不幸的是我找不到任何基准如何!important 可能会影响性能。

Just my thoughts, unfortunately I couldn't find any benchmarks on how !important could affect performance.

这篇关于是重要的性能坏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆