ie6兼容问题2——3像素间距

     在一行两列布局时,当只有一个块状元素有浮动属性时,在ie6浏览器下,此两列之间会产生3px的间隙(其他浏览器正常)。如下图所示:

高版本浏览器:

ie6中          :

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title></title>
    <style type="text/css">
       .left{width: 200px; height: 100px; float: left; background-color: #f70;}
       .right{background-color: #fff; height: 100px; border: 1px solid red;}
    </style>
</head>
<body>
<div>
    <div class="left">left</div>
    <div class="right">right</div>
</div>
</body>
</html>

解决方案:

1.给未设置浮动的元素设置浮动。不推荐,因为此方法会使该元素的宽度为内容宽度,不是自适应布局了;

2.给设置了浮动的元素加上margin-right:-3px;

3.加上ie6的hack方法,给未浮动元素设置_position:relative;_left:-3px; 。

 

posted @ 2015-07-14 18:30  3408GoGoGo  阅读(150)  评论(0编辑  收藏  举报