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

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

作者: 小黄不头秃 | 来源:发表于2022-06-19 00:40 被阅读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>

相关文章

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/sewkmrtx.html