兼容性—IE6下当元素浮动设置margin时会有双边距

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body{
            margin: 0;
        }
        div{
            width: 100px;
            height: 100px;
            background: red;
            margin-left: 50px;
            float: left;
        }
    </style>
</head>
<body>
    <div>div1</div>
</body>
</html>

解决方案:给元素加上display:inline。

div{
            width: 100px;
            height: 100px;
            background: red;
            margin-left: 50px;
            float: left;
            *display: inline;
}

 

posted @ 2017-05-14 17:30  影子疯  阅读(171)  评论(0编辑  收藏  举报