方法一: 使用clear属性的空元素

<div style="clear:both;"></div>

方法二:使用overflow属性

给浮动的元素容器添加overflow:hidden/auto;

在添加overflow属性后,浮动元素又回到了容器层,把容器层撑起来,达到清理浮动的效果

另外在 IE6 中还需要触发 hasLayout ,例如为父元素设置容器宽高或设置 zoom:1。

方法三:给浮动元素后边的元素添加clear元素

方法四:使用css的:after伪元素

.clearfix:after {

   content:'020';

   display:block;

   height:0;

   clear:both;

   visibility:hidden;

}

.clearfix {

   zoom:1;

}

 

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-06-29
  • 2021-04-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2021-10-07
  • 2021-11-02
  • 2021-06-20
  • 2021-06-06
相关资源
相似解决方案