浮动的清除方法

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<html>
<style>
    .box {
        width: 200px;
        background: #bfa;
        border: 2px dashed red;
    }

    .box2 {
        width: 100px;
        height: 100px;
        margin: 20px;
        background-color: orange;
        float: right;
    }

    .box3 {
        width: 100px;
        height: 100px;
        margin-top: 10px;
        background-color: rgb(206, 188, 154);
    }
  
    clearfix::after,
    clearfix::before {
        content: '';
        display: table;
        clear: both;
    }
  
    .clearfix::before,
    .clertfix::after {
        content: '';
        display: table;
        clear: both;
    }
</style>

<body>
    <div class="box clearfix">
        <div class="box2"></div>
        <div class="box3"></div>

    </div>
</body>
</html>

 

posted @ 2022-10-09 23:17  小忱  阅读(28)  评论(0)    收藏  举报