css - IE11 - Flex 子项占据全高

标签 css flexbox internet-explorer-11 styling

我在 IE11 上使用 Flexbox 时遇到问题。

我想做的是让一位 parent 带着 3 个 child 。一个固定大小的页眉,一个固定大小的页脚,内容区域之间应占据剩余空间。

这是代码 - 它适用于 Chrome,但不适用于 IE11:

.parent {
  display: flex;
  flex-direction: column;
  max-height: 500px;
}

.header {
  flex: 0 0 auto;
  background: red;
  height: 50px;
}

.content {
  background: yellow;
  flex: 1 1 auto;
  position: relative;
  overflow-y: scroll;
}

.footer {
  flex: 0 0 auto;
  background: blue;
  height: 50px;
}

.long-item {
  height: 2000px;
}
<div class="parent">
  <div class="header">Header</div>
  <div class="content">
    <div class="long-item">Content</div>
  </div>
  <div class="footer">Footer</div>
</div>

我已经解决了 Unresolved 问题,但找不到真正的解决方案。

最佳答案

这是 IE 的 Flex 错误之一,即使用 Flex 方向 column 时的 min-height “错误”。

在您的情况下,将 display: flex 添加到 body 并将 flex-grow: 1; 添加到 parent (flex-basis: 100%width: 100% 也可以)。

body {
  display: flex;
}

.parent {
  flex-grow: 1;           /*  fill horizontal space */
  display: flex;
  flex-direction: column;
  max-height: 500px;
}

.header {
  flex: 0 0 auto;
  background: red;
  height: 50px;
}

.content {
  background: yellow;
  flex: 1 1 auto;
  position: relative;
  overflow-y: scroll;
}

.footer {
  flex: 0 0 auto;
  background: blue;
  height: 50px;
}

.long-item {
  height: 2000px;
}
<div class="parent">
  <div class="header">Header</div>
  <div class="content">
    <div class="long-item">Content</div>
  </div>
  <div class="footer">Footer</div>
</div>

关于css - IE11 - Flex 子项占据全高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45996623/

相关文章:

css - CSS 文件 AjaxControlToolkit 在哪里?

html - 如何使用 flexbox 在每个断点处居中 div?

javascript - 脚本延迟在 IE11 上不起作用

javascript - 如何通过点击不同的按钮显示不同的元素

html - Bootstrap 3 with Less - 我如何设法使容器水平和垂直居中

javascript - 单击按钮,向 div 添加一些文本和数字。不起作用

html - 右侧的 CSS flex div 图片

html - 如何使用 Bootstrap 4 在 "col-sm-12"中垂直居中我的文本?

asp.net-mvc-4 - 无法从 IE11 登录 Web 应用程序

javascript - MutationObserver 在 IE11 中挂起