Fixed the bug of overflow using CSS attribute in IE.

Source: Internet
Author: User

We need to create an HTML file for testing. The following are the key points: Code Fragment

Copy code The Code is as follows: <div>
<PRE> <code>
<A href = "http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" rel = "License"> abide by my copyright </a>
<A href = "http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" rel = "License"> abide by my copyright </a>
<A href = "http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" rel = "License"> abide by my copyright </a>
<A href = "http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" rel = "License"> abide by my copyright </a>
<A href = "http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" rel = "License"> abide by my copyright </a>
</Code> </PRE>
</Div>

In the above code, I will apply the following CSS

Copy code Code: div {
Width: 60%;
}

Pre {
Overflow: auto;
Background-color: # fff0f5;
Margin: 1.6em 0;
Padding: 0 1.6em;
}

The above code is displayed in Firefox as expected.

However, in IE6, no Overflow Effect is displayed.

Figure 1 Effect of IE6

The display in IE7 is somewhat different, with an annoying scroll bar on the right.

Figure 2 Effect of IE7

The IE6 bug can be solved by adding width to the containing block, that is

Copy code The Code is as follows: Pre {
Overflow: auto;
Background-color: # fff0f5;
Margin: 1.6em 0;
Padding: 0 1.6em;
Width: 90%;
}

At this time, the scroll bar of IE6 is displayed, but it is the same as that of IE7, with an additional scroll bar on the right.

The reason for adding one more scroll bar to the right is that IE always adds the bottom scroll bar to the interior of the element's total height, so that part of the height of the element is occupied by the bottom scroll bar and cannot be completely displayed, therefore, ie automatically adds the scroll bar on the right to make the content blocked by the element scroll and see it.

Finally, to remove the scroll bar on the right side of IE, we add the following CSS to the containing block.Copy codeThe Code is as follows: Pre {
Overflow: auto;
Background-color: # fff0f5;
Margin: 1.6em 0;
Padding: 0 1.6em;
Width: 90%;
Overflow-Y: hidden;
}

In this way, we created the same overflow: auto effect as Firefox, opera, and safari in IE.

in practice, this effect can be applied to all elements in fixed format (usually pre elements), and the most common is the code block.

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.