css - IE7 float 在其父位置为 :relative 时消失

标签 css internet-explorer-7 css-float css-position

这是我在使用 IE7 时遇到的问题的精简版。在所有其他(较新的)浏览器中,这显示正常...为什么 position:relative;float: right; 有影响或 float: left; ?有没有办法保留 position: relative在不牺牲 float 功能的情况下?

JS fiddle :http://jsfiddle.net/uW7JV/2/

没有position: relative; enter image description here

position: relative; (红框内) enter image description here

更精简的版本:http://jsfiddle.net/uW7JV/4/

有趣...删除 <div class="clearboth"></div>允许显示内容。但是,我确实需要那里的功能,所以我仍在寻找修复方法。 http://jsfiddle.net/uW7JV/9/

最佳答案

您需要添加 overflow: hidden.column-wrapper以便它包裹它漂浮的 child 。你不需要 .clearboth div 和 CSS 在你这样做之后。

您需要解决的另一个问题是列宽,因为 box-sizing: border-box在 IE7 中不受支持,分配 width 时需要考虑填充.

div {
    padding: 5px 1%;
}
.column-wrapper {
    background: orange;
    position: relative;
    overflow: hidden;
}

.main {
    background: yellow;
    float: right;
    width: 64.6%;
}
.sidebar {
    float: left;
    background: green;
    width: 31.3%;
}

演示:http://jsfiddle.net/myajouri/uW7JV/15/

解决此问题的另一种方法是使用 Clearfix hack

.clearfix {
  zoom: 1; /* for IE6/7 */
}

.clearfix:after {
  content: "";
  display: table;
  clear: both;
}

然后添加 clearfix类别为 .column-wrapper .

关于css - IE7 float 在其父位置为 :relative 时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20526011/

相关文章:

javascript - 如何使 css 列环绕一个切口

css - float 元素前不显示标题

css - float 元素进入下一个框

html - 对齐 css 菜单文本左 besie 菜单图像

html - float Div 列表不能正确显示自动高度

css - 有没有办法设置 iOS Safari 过度滚动/flex 滚动区域的样式?

html - 边距不适用于我的图像

javascript - bootstrap carousel - 滑动时暂停 html 视频

IE7 中的 Jquery 滚动问题

CSS 菜单在 IE7 或更低版本中不起作用