日期:2014-05-17  浏览次数:20741 次

ie css bug 总结
在开发中我们常会在ie中遇到很多莫名的bug,尤其是ie6这个早就该退出历史的浏览器。刚刚在haslayout.net上看到有总结ie的一些 bug,分享一下。

1.图片label bug,影响版本ie6/ie7/ie8,当label中有img的时候无法触发点击选中form元素事件.
demo [url=http://haslayout.net/demos/Image-Label-Focus-Bug-Demo.html]http://haslayout.net/demos/Image-Label-Focus-Bug-Demo.html[/url]
fix demo [url=http://haslayout.net/demos/Image-Label-Focus-Bug-Fixed-Demo-CMS.html]http://haslayout.net/demos/Image-Label-Focus-Bug-Fixed-Demo-CMS.html[/url]
解决方案:通过给<label>内加入一个空的span标签,然后设置 position:absolute;background:url(#); 设置label float:left; position:relative;overflow:hidden;就可以解决了

2.设置margin auto的button没有居中,影响版本ie8,ie8下,如果给像button这样的标签(如button input[type="button"] input[type="submit"])设置{ display: block; margin-left: auto; margin-right: auto; }如果不设置宽度的话无法居中。
demo [url=http://haslayout.net/demos/No-Auto-Margin-Center-on-Buttons-Inconsistency-Fixed-Demo-CS.html]http://haslayout.net/demos/No-Auto-Margin-Center-on-Buttons-Inconsistency-Fixed-Demo-CS.html[/url]
解决方案:可以给button加上宽度,或是通过js,var buttons = document.getElementsByTagName(’button’); for ( var i = 0; i < buttons.length; i++ ) {
buttons[i].style.width = buttons[i].offsetWidth + ‘px’;
}
另一种解决方案:
<form action=”">
<div>
<button>This button should be centered</button>
<div class=”ie_fix”>
<input type=”button” value=”This button should be centered”>
</div>
<input type=”text”>
<input type=”checkbox”>
<input type=”radio”>
<div class=”ie_fix”>
<input type=”submit” value=”This button should be centered”>
</div>
<input type=”file”>
<select><option>test</option></select>
</div>
</form>

button, select, input {
display: block;
margin-left: auto;
margin-right: auto;
width: auto;
}
.ie_fix {
text-align: center;
}
.ie_fix input[type="submit"],
.ie_fix input[type="button"] {
display: inline-block;
}
<!–[if IE 8]>
<style type=”text/css”>
button { display: table; }
</style>
<![endif]–>

给 input[type="button"] input[type="submit"]加上一个额外的标签,并设置display:inline-block;
并通过条件注释给ie8下设置button display:table;

3.不正确的浮动伸展布局,影响版本ie6/ie7,连续浮动的元素并且设置clear属性没法自动伸展
demo [url=http://haslayout.net/demos/Incorrect-Float-Shrink-Wrap-Bug-Demo.html]http://haslayout.net/demos/Incorrect-Float-Shrink-Wrap-Bug-Demo.html[/url]
fix demo [url=http://haslayout.net/demos/Incorrect-Float-Shrink-Wrap-Bug-Fixed-Demo.html]http://haslayout.net/demos/Incorrect-Float-Shrink-Wrap-Bug-Fixed-Demo.html[/url]
解决方法:给连续浮动元素加一个span然后设置display:inline-block和display:block

4.文档滚动bug,影响版本ie6/ie7,不在html标签上设置overflow或许会影响到body上面的overflow
具体请看[url=http://haslayout.net/css/Document-Scrollbars-Overflow- Inconsistency]http://haslayout.net/css/Document-Scrollbars-Overflow-Inconsistency[/url]

5.连续浮动元素bug,影响版本ie6/ie7,[url=http://haslayout.net/css/Float-Squeeze- Weird-Gap-Bug]http://haslayout.net/css/Float-Squeeze-Weird-Gap-Bug[/url]

6.连续浮动字符出现重复字符,影响版本ie6/ie7,[url]http://haslayout.net/css/Float-Squeeze- Duplicate-Last-Character-Bug[/url]
这个和5的解决方案都差不多,5是通过加一个宽度,而这个是通过给浮动字符加一个position:relative;

7.空元素高度bug,影响版本ie6/ie7,有layout的空元素获得了高度
<div></div>div {
background: blue;
width: 100%; /* to give “layout”??*/
}

解决办法:
div {
height: 0;
overflow: hidden;
background: blue;
width: 100%; /* this is just what we originaly had as “layout” giver */
}

8.表单元素双margin bug,影响版本ie6/ie7,input和textarea或许会继承父元素的水平的margin
具体请看[url=http://haslayout.net/css/Form-Control-Double-Margin-Bug]http: //haslayout.net/css/Form-Control-Double-Margin-Bug[/url]

9.ie7的1px dotted 边框变成dashed边框的bug,影响版本ie7, 当设置了1px dotted边框后,有一个边框的宽度大于1px
的话其它为1px边框会变为dashed的样式,具体请看[url=http://haslayout.net/css/IE7-1px-Dotted- Border-Appears-As-Dashed-Bug]http://haslayout.net/cs