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;
}



原文地址:https://www.cnblogs.com/yuesu/p/10526372.html