Why not use CSS expression?

Source: Internet
Author: User

CSS expressions (CSS expression) is a very powerful method that allows you to dynamically set attributes on a page, but it has poor compatibility and also has a terrible weakness;

You can use a function expression in Javascript in CSS expressions. To dynamically set the page style. It can also solve some experience in earlier ie browsers.

 

Supporter: ie5 to IE7 browser.

 

 

For example, IE6 does not support applying the height: 100% attribute of position: absolute. Available:Height: expression (it. parentnode. offsetheight + 'px ';);

For example, you can use CSS expressions to control the color changes every hour:Background-color: expression (new date (). gethours () % 2? "# B8d4ff": "# f08a00 ");

 

However, this method has a terrible hidden danger. It will frequently calculate (beyond the expectation of most designers );

In the following cases, CSS expressions are frequently executed.

1. When the webpage is opened. (<10 times)

2. Reset the browser size each time. (Once)

3. Pull and set the browser size. (One pixel per pull)

4. Move the mouse over the text area on the page (one pixel per mouse)

When the CSS expressions page is used, the CSS expression is easily calculated for tens of thousands of times, leading to machine slowdown, browser freezing, and high CPU occupation.

 

Demo of the number of tests and computations (see IE6 and IE7 .)

 

 

Therefore, if the page style attribute must be set dynamically, you can use JavaScript to implement it. CSS expressions is not recommended;

If you must use a CSS expression, do not forget that it may generate thousands of computations at the same time.
Affects the effect of your entire page;

 

 

 

 

 

 

Related Article

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.