夜阑卧听风吹雨,铁马冰河入梦来。

IE6双倍边距BUG

2011-10-31

在IE6中,如果块元素设置float:left/right,并设置margin-left/right时,边距就会翻倍。

html代码如下:

<div class="out">
<div class="in"></div>
<div style="clear:both"></div>
</div>


CSS代码如下:

.out {border:1px solid #0cf; width:300px;}
.in { width:200px;
      height:100px;
      border:1px solid #000;
      margin:10px;
      float:left}

浏览器输出结果:

firefox,Ie7,8,9显示效果

firefox,Ie7,8,9显示效果

 

IE6

IE6下显示效果(边距翻倍了)

 

解决方法:添加display:inline;属性(推荐!)。或者使用_margin-left/right:5px(正常值的一半,目前只有IE6能解析),即可解决。

更改后CSS代码如下:

.out {border:1px solid #0cf; width:300px;}
.in {
    width:200px;
    height:100px;
    border:1px solid #000;
    margin:10px;
    float:left;
    display:inline}

值得注意的是使用margin-top/margin-bottom不会出现问题。

 

作者:admin | 分类目录:html+css | 标签:

发表评论

电子邮件地址不会被公开。

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>