Fixed the Bug_ experience Exchange using CSS properties overflow under IE

Source: Internet
Author: User
We're going to build a test HTML file, and here's the key piece of code

Copy Code code 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 as follows:

div{
width:60%;
}

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

The above code in the Firefox display is predictable.

But in IE6, no overflow effect can be shown.

Fig. 1 Effect under IE6

And the display in the IE7 is also somewhat different, with a more annoying right scroll bar

Fig. 2 Effect under IE7

IE6 bugs can be resolved by adding a width to the containing block, namely

Copy Code code as follows:

pre{
Overflow:auto;
Background-color: #fff0f5;
Margin:1.6em 0;
Padding:0 1.6em;
width:90%;
}

At this point, the IE6 scroll bar comes out, but it is the same as the IE7, with one more right scroll bar.

One more right scroll bar is the reason: ie always adds the bottom scroll bar to the inside of the total height of the element, so that part of the element height is occupied by the bottom scroll bar and cannot be fully displayed, so IE automatically adds the right scroll bar so that the elements are blocked and can be scrolled.

Finally, to remove the scroll bar on the right side of IE, we add the following CSS to containing block
Copy Code code as follows:

pre{
Overflow:auto;
Background-color: #fff0f5;
Margin:1.6em 0;
Padding:0 1.6em;
width:90%;
Overflow-y: Hidden;
}

So we created the same overflow:auto effect as Firefox, Opera and Safari in IE.

In practice, this effect can be applied to all fixed-form elements (usually the pre element), most commonly a block of code.

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.