清除浮动的方法

匿名 (未验证) 提交于 2019-12-02 20:37:20
  • 最早的一种方式,支持 IE6
<style>     .box {         background-color: gray;         border: solid 1px black;     }          .box .img {         float: left;         width: 100px;         height: 100px;     }          .clearfix {         *zoom: 1;     }              .clearfix:after {         content: "020";         display: block;         height: 0;         clear: both;         visibility: hidden;     } </style> <div class="box clearfix">     <div class="img"></div> </div>
  • 添加无用标签,不易维护。
<style>     .box {         background-color: gray;         border: solid 1px black;     }          .box .img {         float: left;         width: 100px;         height: 100px;     }          .clear {         clear: both;     } </style> <div class="box clearfix">     <div class="img"></div>     <div class="clear"></div> </div>
  • 现在最流行的一种方式
  • 同时可以解决上下外边距合并问题
  • 可以参考博客中的BFC、IFC、GFC、FFC
<style>     .box {         background-color: gray;         border: solid 1px black;         overflow: hidden;     }          .box .img {         float: left;         width: 100px;         height: 100px;     } </style> <div class="box">     <div class="img"></div> </div>
文章来源: 清除浮动的方法
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!