28、使用 CSS 解决外边距重叠和高度塌陷的问题(after、

2022-06-19  本文已影响0人  小黄不头秃

clearfix可以解决外边距重叠和高度塌陷的问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>clearfix</title>
    <style>
        .box1{
            border: red solid 5px;
        }
        /* .box1::before{
            content: "";
            display: table;
        } */
        .box2{
            width: 200px;
            height: 200px;
            background-color: orange;
            float: left;
        }
        .clearfix::before ,
        .clearfix::after{
            content: "";
            display: table;
            clear: both;
        }

    </style>
</head>
<body>
    <!-- clearfix可以解决外边距重叠和高度塌陷的问题 -->
    <div class="box1 clearfix">
        <div class="box2 "></div>
    </div>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读