1 对于儿子块float后,父亲块如果没内容就不见了,如何让父亲块依然跟随飘起了的儿子块撑起来呢??

用到的属性after方法  公共方法作为继承即可。

1.1  方法1 clear + visibility + height

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .clearfix:after{
            content: '111';
            display: block;
            clear: both;
            visibility: hidden; /* 将块内的内容隐藏*/
            height: 0;
        }
        .c{
            background-color:red;
        }
        .c .item{
            float:left;
            width:30px;
            height: 70px;
            background-color: green;
        }

        .test{
            background-color: red;
        }
        .test:after{
            content: "";
        }
        .test:before{
            content: '';
        }
    </style>
</head>
<body>
    <div class='c clearfix'>
        <div class='item'>123</div>
        <div class='item'>456</div>
    </div>

    <!--<div class="test">内容</div>-->
</body>
</html>
clear visibility height

相关文章:

  • 2021-12-23
  • 2022-02-26
  • 2021-06-01
  • 2021-11-11
  • 2021-12-09
  • 2021-09-28
  • 2022-12-23
猜你喜欢
  • 2021-10-30
  • 2021-12-19
  • 2021-09-20
  • 2021-04-04
  • 2022-12-23
  • 2021-12-16
相关资源
相似解决方案