How to resolve exceptions caused by transparent Settings Using filters in IE 6/7/8/9

Source: Internet
Author: User

As follows: Copy codeThe Code is as follows: <div style = "width: 100px; height: 100px; background: gold"> </div>

Use the IE developer tool or the developer tool that comes with IE8. The structure is shown in Figure 1:

The Inline style width, height, and background added to the div are arranged in sequence. Normal!

However, after you add filter: alpha (opacity = 20) to the div,

Copy codeThe Code is as follows: <div style = "filter: alpha (opacity = 20); width: 100px; height: 100px; background: gold">
</Div>

The situation has changed, as shown in Figure 2:

As you can see in the Red Circle, width and filter are crowded on a row. Normally, the width should start with another line.
Some people may say that this is only because the developer tool is not correctly displayed, as long as it does not affect the correct rendering of page elements.
Indeed, in IE6/7/8/9, the width, height, background color, and transparency of the element can all be rendered as expected.

In addition, writing styles in style labels or css files also produces the above phenomenon.

Let's take a look at setting filter in JS. The situation is slightly different. The Code is as follows:

Copy codeThe Code is as follows: <! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> set filter for JS in IE 6/7/8/9 </title>
</Head>
<Body>
<Div id = "d1" style = "width: 100px; height: 100px; background: gold"> </div>
<Script type = "text/javascript">
Var d1 = document. getElementById ('d1 ');
D1.style. filter = 'Alpha (opacity = 20 )';
</Script>
</Body>
</Html>

IE to view the structure, the effect is shown in figure 2, that is, the filter and width are in one row.

Note the last JavaScript code in the above htmlCopy codeThe Code is as follows: d1.style. filter = 'Alpha (opacity = 20 )';

No plus points after the right parentheses. This sentence is now slightly changed (it is indeed slightly changed, only a semicolon is added)Copy codeThe Code is as follows: d1.style. filter = 'Alpha (opacity = 20 );';

That is, a semicolon ";" is added after the parentheses ";". View the IE developer tool as shown in Figure 3:

The four css attributes background, filter, height, and width are displayed in one row. The filter and width values in Figure 2 are not displayed in one row.

PS: many popular JS libraries do not contain semicolons After alpha (opacity = 20.

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.