html - IE11 flex 元素垂直溢出

标签 html css flexbox internet-explorer-11

我知道这里的 IE 问题中有很多 flex item overflow,但是我找不到垂直溢出答案的解决方案。

如果您在 Chrome 中运行,您会看到内容垂直滚动并带有内部滚动条,它遵循父级的 max-height。 (预期)

但是,如果您在 IE 11 中运行,它会溢出而不是创建内部滚动。

有什么想法吗?

编辑:一些上下文,我正在尝试创建一个模态,其中对话框具有自动高度并增长到最大高度,然后在正文中设置内部滚动。类似于 https://material-ui.com/demos/dialogs/#scrolling-long-content 的东西. (滚动=纸)

不确定他们是如何让 IE 工作的

.container {
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  background: blue;
}

.body {
  overflow-y: auto;
  flex: 1 1 auto;
}

.content {
  width: 200px;
  height: 1200px;
}
<div class="container">
  <div class="header">aa</div>
  <div class="body">
    <div class="content">
      content
    </div>
  </div>
  <div class="footer">ccc</div>
</div>

最佳答案

只需将 max-height: calc(100vh - 50px); 添加到 .body(我假设页眉 + 页脚 = 50px)。

.container {
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  background: blue;
}

.body {
  max-height: calc(100vh - 50px);
  overflow-y: auto;
  flex: 1 1 auto;
}

.content {
  width: 200px;
  height: 1200px;
}
<div class="container">
  <div class="header">aa</div>
  <div class="body">
    <div class="content">
      content
    </div>
  </div>
  <div class="footer">ccc</div>
</div>

另一种方法是将 height: 100% 设置为 .container (我不确定为什么它在我创建 html 文件并在 IE 中运行时运行良好,但不是在此处使用 html 片段)

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: blue;
}

.body {
  overflow-y: auto;
  flex: 1 1 auto;
}

.content {
  width: 200px;
  height: 1200px;
}
<div class="container">
    <div class="header">aa</div>
    <div class="body">
        <div class="content">
            content
        </div>
    </div>
    <div class="footer">ccc</div>
</div>

关于html - IE11 flex 元素垂直溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53529878/

相关文章:

javascript - 如何在javascript中删除单词后的所有字符串?

html - Angular Kendo - 在 CSS 或 SCSS 中设置网格列宽

html - -Windows Phone 中的 webkit-tap-highlight-color?

javascript - 使下拉菜单项始终与其父项具有相同的大小? ( Bootstrap 和 CSS)

javascript - 如何清除和更改 Canvas 的背景颜色?

php 代码在 html 中不起作用

html - Bootstrap 4 自定义复选框缺少高度

html - Flex/Grid 布局不适用于按钮或字段集元素

html - 防止最后一项拉伸(stretch)以填满容器

javascript - 如何在一定时间延迟后清空输入字段?