css - IE11 中的 Flexbox 不填充高度

标签 css flexbox internet-explorer-11

我有这个案例:

http://codepen.io/anon/pen/radoPd?editors=110

这是 CSS 代码:

.wrapper{
  background-color: red;
  min-height: 100vh;
  display: flex;
}

.sidebar{
  background: orange;
  flex: 0 0 300px;
}
.main{
  background-color: green;
  overflow-y: scroll;
}

出于某种原因,在 IE11 上,.sidebar 和 .main 区域都不会填满包装器的整个高度。

这是浏览器之间的不一致。这是一个错误吗?我错过了什么吗?

最佳答案

这是一个已知的IE bug不幸的是,它已被 IE 团队关闭为 Won't Fix 并描述如下:

In all other browsers that support flexbox, a flex-direction:column based flex container will honor the containers min-height to calculate flex-grow lengths. In IE10 & 11-preview it only seems to work with an explicit height value.

据我所知,尽管有此描述,但当 flex-directionrow 时,该错误也适用。正如评论中提到的,Philip Walton 提出了一个解决方案 here ,其中包括将高度设置为固定值,但这不是 OP 的选项。

作为解决方法,我建议也为 main 元素设置一个 min-height: 100vh:

.wrapper{
  background-color: red;
  min-height: 100vh;
  display: flex;
}

.sidebar{
  background: orange;
  flex: 0 0 300px;
}
.main{
  background-color: green;
  min-height: 100vh;
}

here .

关于css - IE11 中的 Flexbox 不填充高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28627879/

相关文章:

html - CSS flex :column. 不占用父级的全宽

html - IE11 - border-radius 和 box-shadow 一起导致问题

html - Flexbox 垂直对齐不起作用

html - 外部 div 宽度与内部段落宽度不匹配

html - 使用CSS调整浏览器窗口大小时如何使子div可滚动

html - angular material layout-align space-between 在 IE 中不起作用

html - 当周围的元素增长时,伪元素的大小会减小

css - 可变宽度的 flex 元素之间的等距分隔符

html - 应用于 anchor 标记的相同类 IE 11 生成两个不同的背景图像

html - 如何重新设计或删除按钮(聚焦)的内边框