daily-interview/fe-interview

有哪几种常用的清除浮动方法?

artdong opened this issue · 1 comments

有哪几种常用的清除浮动方法?

  • 父级元素添加伪元素
.clear-float:after {
    content: '';
    display: block;
    clear: both;
}
  • 在与浮动元素平级的最后面添加新元素 div.clear
.clear {
    clear: both;
}
  • 在父级元素添加样式 overflow: auto; 或者 overflow: hidden; 会存在兼容性问题。