css 清除浮动

时间:2020-03-18 13:23:23   收藏:0   阅读:46

title: css 清除浮动
date: 2020-03-10 17:03:10
tags: css


清除浮动

清除浮动的方法

  1. 在浮动元素同级最后增加一个冗余元素为其设置 clear:both

    clear的取值可以是:left、right、both

    • 清除左边浮动
    • 清除右边浮动
    • 左右浮动都不要
    .clear{clear:both; height: 0; line-height: 0; font-size: 0}
  2. 给父元素增加

    overflow: hidden;
    // 或者设置overflow: auto;只要overflow不为visible即可
    zoom: 1; //解决浏览器兼容问题
  3. :after 方法

    .outer {
        zoom:1;
    }    /*==for IE6/7 Maxthon2==*/
    .outer :after {
        clear:both;
        content:'';
        display:table;
        width: 0;
        height: 0;
        visibility:hidden;
    }

块格式化上下文(BFC)

原文:https://www.cnblogs.com/serahuli/p/12516610.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!