1. Centering elements
Centering an element is a problem that many front-end developers encounter when setting up the same type of setup. The simplest way to center is to set theMargin:autoon the related element. This method can be centered without considering the width of the parent element. No, the IE6 in the weird mode is missing the effect we want.
Please look at the following codes:
#container{ border: solid 1px #000; background: #777; width: 400px; height: 160px; margin: 30px 0 0 30px;}#element{ background: #95CFEF; border: solid 1px #36F; width: 300px; height: 100px; margin: 30px auto;}
The effect you want to see:
IE shows the results:
This is because IE6 strange mode or the early version of IE is not aware of the problem of Margin:auto , but this problem is very easy to repair.
Method:
The simplest and most reliable way to center the IE6 is to add text-align:centerto the parent element, adding text-align:left to the centering element to ensure that the text is aligned correctly
#container{ border: solid 1px #000; background: #777; width: 400px; height: 160px; margin: 30px 0 0 30px; text-align: center;}#element{ background: #95CFEF; border: solid 1px #36F; width: 300px; height: 100px; margin: 30px 0; text-align: left; }
2. Ladder effect
Most of the developers will use list in navigation linked fields. Usually we create containers, add some <a> tags to it, and then set <a> float. However, in IE, the situation is more complicated as follows:
<ul> <li><a href="#"></a></li> <li><a href="#"></a></li> <li><a href="#"></a></li></ul>ul { list-style: none;} ul li a { display: block; width: 130px; height: 30px; text-align: center; color: #fff; float: left; background: #95CFEF; border: solid 1px #36F; margin: 30px 5px;}
Usually the browser renders this:
And in IE it shows:
It doesn't look so good, but there are two ways we can fix this problem.
Method 1:
Set the LI element to float instead of <a> float
ul li { float: left;}
Method 2:
Setup the LI element display:inline. Not only does this solve the problem, but it also solves the problem of the double margin we're going to be talking about. Some people may not like the idea of placing a class element in a line element.
ul li { display: inline}
3. Float-generated double margins
Let an element have a margin effect in the floating direction to touch this bug
#element{ background: #95CFEF; width: 300px; height: 100px; float: left; margin: 30px 0 0 30px; border: solid 1px #36F;}
The normal browser shows the effect:
IE Effect:
The way to resolve this bug is to set the display of the floating element to inline:
#element{ background: #95CFEF; width: 300px; height: 100px; float: left; margin: 30px 0 0 30px; border: solid 1px #36F; display: inline;}
4. Element cannot be set to a smaller height
Sometimes, we need to set the element to a smaller height. Usually we just need to set HEIGHT:XXPX to get to the end. But on IE, we may get double height.
#element{ background: #95CFEF; border: solid 1px #36F; width: 300px; height: 2px; margin: 30px 0;}
We want to get this effect: an element with a 1px margin and a height of 2px.
But in IE:
The reason for this bug is that IE refuses to let the height of the element be smaller than the font-size. So set the Font-size to 0 and then we can set a small size height
#element{ background: #95CFEF; border: solid 1px #36F; width: 300px; height: 2px; margin: 30px 0; font-size: 0;}
But there is a better way to do this by setting Overflow:hidden .
#element{ background: #95CFEF; border: solid 1px #36F; width: 300px; height: 2px; margin: 30px 0; overflow: hidden}
5. Auto Overflow and relative positioning elements
This bug appears when the overflow of the parent element is auto and the element containing position is relative. The relative positioning element broke the boundary of the parent element.
<div id="element"><div id="anotherelement"></div></div>#element{ background: #95CFEF; border: solid 1px #36F; width: 300px; height: 150px; margin: 30px 0; overflow: auto;}#anotherelement{ background: #555; width: 150px; height: 175px; position: relative; margin: 30px;}
Desired Effect:
IE Effect:
Workaround: Set the parent element's position as relative
#element{ background: #95CFEF; border: solid 1px #36F; width: 300px; height: 150px; margin: 30px 0; overflow: auto; position: relative;}
6. Broken Box model
7. Set the minimum width and height
IE ignores the min-height of this
Solution 1: Use !important to hack
#element { min-height:150px; height:auto !important; height:150px;}
Method 2: Use IE cannot parse the properties of the sub-selector
#element { min-height: 150px; height: 150px;}html>body #element { height: auto;}
8. The wrong behavior of the floating agency
Create a no-table layout an important concept is floating. In most cases, the IE6 is still poorly handled. But when it comes to what is not broken or if the width of the element is over the width of the parent element, the following question
<div id="container"> <div id="element">http://net.tutsplus.com/</div> <div id="anotherelement"></div></div>#element, #anotherelement{ background: #95CFEF; border: solid 1px #36F; width: 100px; height: 150px; margin: 30px; padding: 10px; float: left;}#container{ background: #C2DFEF; border: solid 1px #36F; width: 365px; margin: 30px; padding: 5px; overflow: auto;}
Expect:
In IE:
We can see that the first Div stretched itself to fit its own content.
There is no good way to do this bug, but we can set Overflow:hidden to save our agency.
#element{ background: #C2DFEF; border: solid 1px #36F; width: 365px; margin: 30px; padding: 5px; overflow: hidden;}
9. Gaps in the list
IE6 adds some vertical space between the list elements.
<ul> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li></ul>ul { margin:0; padding:0; list-style:none;}li a { background: #95CFEF; display: block;}
They should look like this:
ie under effect:
Method 1:
li a { background: #95CFEF; display: block; width: 200px;}
Method 2:
li a { background: #95CFEF; float: left; clear: left;}
Method 3:li {display:inline;}
Some bugs about IE