Css! Does impant ant rules affect performance?

Source: Internet
Author: User

Recently, many CSS codes have been used in projects! Important overwrites the original high-priority style. Generally, the more flexible things you need to do, the more work you need. So I think it is like! Important is a flexible and convenient rule. If it is used more often, it will definitely affect the performance. Based on this consideration, we wanted to remove all these styles by raising their priorities. But later I thought about it, I 'd like to google it. I guess it is generally unreliable. So I found this article Is! Important bad for performance ?. Below is the general meaning:

The CSS Parsing Code of firefox/Source/layout/style/nsCSSDataBlock. cpp #562 the important processing is as follows:

if (aIsImportant) {    if (!HasImportantBit(aPropID))      changed = PR_TRUE;    SetImportantBit(aPropID);  } else {    // ...

Source/layout/style/nsCSSDataBlock. h #219 The following comments describe the above Code:

 /**     * Transfer the state for |aPropID| (which may be a shorthand)     * from |aFromBlock| to this block.  The property being transferred     * is !important if |aIsImportant| is true, and should replace an     * existing !important property regardless of its own importance     * if |aOverrideImportant| is true.     *      * ...     */

As you can see above, firefox is! The important rule is easy to judge: it will include! The important style directly overwrites the normally generated style rules, and if it is resolved to the back, there will be! When the impant ant rule is used, the priority is compared with that of the previous impant ant rule. That is to say, use! The CSS rules of important are set to the highest priority, and then the pattern to be applied is determined in the highest priority.

The conclusion is: use! Important has no negative impact on performance. However, this rule is rarely used in terms of maintainability. However, this rule is not fully supported by IE6 bug (IE6 IE7 (Q) IE8 (Q! Impant ant rules.

 

References:

Https://developer.mozilla.org/zh-CN/docs/Web/CSS/Specificity

Http://www.w3cplus.com/css/the-important-css-declaration-how-and-when-to-use-it.html

Http://www.w3.org/TR/CSS2/cascade.html#important-rules

Http://w3help.org/zh-cn/causes/RA8003

Http://stackoverflow.com/questions/13743671/is-important-bad-for-performance

Http://www.html5rocks.com/zh/tutorials/internals/howbrowserswork/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.