HTML写盒子浮动和清除

img


盒子的浮动和清除(打东方大厦夫唱妇随到京东快递可大可小慢慢写你擦可擦)

这个布局 还是挺简单的div布局加 浮动就行。或这 flex布局

<!DOCTYPE html>
<html lang="en">

<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>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 100%;
            height: 100%;
        }

        .header {
            width: 100%;
            height: 50px;
            background: blue;
        }
        .content{
            width: 830px;
            margin: 0 auto;
        }
        .content .banner{
            width: 100%;
            height: 100px;
            background: red;
            margin: 10px 0;
        }
        .list{
            width: 100%;
            display: flex;
            justify-content:space-between;
        }
        .list>div{
          width: 200px;
          height: 100px;
          background: red;
        }
        .list1{
            width: 100%;
            display: flex;
            justify-content:space-between;
            margin: 10px 0;
        }
        .list1>div{
          width: 200px;
          height: 200px;
          background: red;
        }
        .footer {
            width: 100%;
            height: 150px;
            background: blue;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="header">

        </div>
        <div class="content">
             <div class="banner"></div>
             <div class="list">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
             </div>
             <div class="list1">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
             </div>
        </div>
        <div class="footer">

        </div>
    </div>

</body>

</html>

float布局

<!DOCTYPE html>
<html lang="en">

<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>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 100%;
            height: 100%;
        }

        .header {
            width: 100%;
            height: 50px;
            background: blue;
        }
        .content{
            width: 830px;
            margin: 0 auto;
        }
        .content .banner{
            width: 100%;
            height: 100px;
            background: red;
            margin: 10px 0;
        }
        .list{
            width: 100%;
            clear: both;
            height: 100px;
        }
        .list>div{
          width: 200px;
          height: 100px;
          background: red;
          float: left;
          margin-right:10px ;
        }
        .list>div:last-child{
            margin-right:0;
        }
        .list1{
            width: 100%;
            clear: both;
            margin: 10px 0;
            height: 200px;
        }
        .list1>div{
          width: 200px;
          height: 200px;
          background: red;
          float: left;
          margin-right:10px ;
        }
        .list1>div:last-child{
            margin-right:0;
        }
        .footer {
            width: 100%;
            height: 150px;
            background: blue;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="header">

        </div>
        <div class="content">
             <div class="banner"></div>
             <div class="list">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
             </div>
             <div class="list1">
                <div></div>
                <div></div>
                <div></div>
                <div></div>
             </div>
        </div>
        <div class="footer">

        </div>
    </div>

</body>

</html>

挺基础的,学一下盒子浮动基础就可以了