CSS魔法(三)

浮动

为何需要浮动?

为何要清除浮动?

  清除浮动本质

  清除浮动主要为了解决父级元素因为子级浮动引起内部高度为0 的问题。

额外标签法

 <div class="clearfix"></div>
.clear {
        clear: both;
        /*如果清除了浮动, 父亲去自动检测孩子的高度  以最高的为准*/
    }

overflow 清除浮动

.father {
        border: 1px solid red;
        width: 300px;
        overflow: hidden;   /*别加错位置了,给 父亲加*/
        /*不是所有的浮动我们都需要清除 ,谁影响布局,我们清除谁*/
    }

猜你喜欢

转载自www.cnblogs.com/cnki/p/9756439.html