几个css清浮动的方法【2012/07/18】

  1. 设置了clear属性的元素,其上边框会紧贴着浮动元素的margin-bottom边界位置渲染,忽略其margin-top设置。
    .clr{
        clear:both;
    }
  2. 空标签清浮动,不推荐。
    <div class="clr"></div>
    .clr{
        clear:both;
        height:0;
        overflow:hidden;
    }
  3. 伪类after清浮动。
    .clr:after{
        content:"";
        height:0;
        line-height:0;
        display:block;
        visibility:hidden;
        clear:both;
    }
     .clr{
        zoom:1;
    }
  4. 使用【display:table】。
  5. 使用overflow除visible,类似于激发haslayout。
  6. 使用浮动父元素清浮动。
原文地址:https://www.cnblogs.com/zhengyingyan/p/3627198.html