css清除浮动(推荐)

为什么要清除浮动呢?

        ---因为子元素设置浮动后,父级元素不能自动被撑开,影响页面布局。

解决方法有很多种,最为推荐一种,其他不多说了,一种足够。

<div  class='parent'> 
     <div class="son"></div>
</div>


.son{
     200px;
     height:100px;  
}

//清除浮动


.parent:after{
            content:"";
            height:0;
            line-height:0;
            display:block;
            visibility:hidden;
            clear:both;
        }
//兼容ie
.parent{
     zoom:1;
}

  

原文地址:https://www.cnblogs.com/lgnblog/p/13292806.html