css - 为 div 容器强制清除流

标签 css css-float css-position overflow

我在我的 test page 上使用此代码清除 header 容器 float ,但不起作用。我能以某种方式强制它吗?

#header-container{
  position: relative !important;
  clear: both !important;
  overflow: auto !important;
}

最佳答案

使用这种方法:

#header-container:after {
  content: ' ';
  line-height: 0;
  display: block;
  clear: both;
  *zoom: 1;       /* trigger hasLayout for IE 6/7*/
}

我还建议看看才华横溢的 Nicolas Gallagher Micro clearfix

更新:

根据 OP 的解释,(在下面的评论中):

That header-container floats on top and stays there when i scroll and i don't want that.

enter image description here

这不是一个清除修复问题,#header-container 的子项都不是 float 的

重点是 .viewitem-panel.viewitem-inner 元素定位留在页面底部,对在标题下,.viewitem-inner 有一个 overflow-y: scroll; CSS 声明来滚动内容。

因此,除非更改布局,否则无法解决此问题。

关于css - 为 div 容器强制清除流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21405161/

相关文章:

html - CSS - 中间有文本的分隔符

javascript - 使用 IE8 的 respond.js 的参数无效

css - 如何在纯 CSS 中创建等高列

css - 由于 hasLayout,如何停止 IE7 清除 float

css - 使用绝对定位使 div 居中

css - 如何处理 chrome 和 firefox 中的 css top 值差异?

html - 如何在图像旁边垂直对齐 DIV?

CSS: Left/Right/Center Example,请解释为什么会这样

css - 向右浮动不适用于我的 Wordpress Mantra 主题

html - 我可以更改位置 : absolute elements? 的 z-index 堆叠顺序吗