清除浮动==双伪元素清除浮动

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    代码简洁
    <style>
       .clearfix:before,
       .clearfix:after {
           content: "";
           display: table;
       }
       .clearfix:after {
           clear: both;
       }
        .clearfix {
            *zoom: 1;
        }

        .box {
            width: 800px;
            border: 1px solid blue;
            margin: 0 auto;
        }

        .damao {
            float: left;
            width: 300px;
            height: 200px;
            background-color: purple;
        }

        .ermao {
            float: left;
            width: 200px;
            height: 200px;
            background-color: pink;
        }

        .footer {
            height: 200px;
            background-color: black;
        }
    </style>

</head>
<body>
    <div class="box clearfix">
        <div class="damao">大毛</div>
        <div class="ermao">二毛</div>
        <div class="ermao">二毛</div>
        <div class="ermao">二毛</div>
        <div class="ermao">二毛</div>
        <div></div>
    </div>
    <div class="footer"></div>
</body>
</html>
上一篇:position: relative


下一篇:Web前端HTML5&CSS3初学者零基础入门——第八天(定位)