css 清除浮动

子标签使用了float时候,父标签的样式失效

解决方案一:clear: both

<div style='background-color:red;'>
    <div style="float: left">div1</div>
    <div style="float: left">div2</div>
    <div style="clear: both;"></div>
</div>

 


解决方案二:clearfix

<div style='background-color:red;' class="clearfix">
    <div style="float: left">div1</div>
    <div style="float: left">div2</div>
</div>
.clearfix:after{
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}

 



posted @ 2019-03-13 21:16  yuesu  阅读(221)  评论(0编辑  收藏  举报