html - 显示 :flex and scrolling inner divs

标签 html css flexbox

https://jsfiddle.net/wqmm0kxb/5/

html:

<div class="full">
  <header><h1>header stuff</h1></header>
  <section>
    <div>
       {lots and lots of content}
    </div>
    <div>b</div>
    <div>c</div>
  </section>
</div>

CSS:

.full {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;

    display: flex;
    flex-direction: column;

   header {
      flex: 78px 0 0;
      background: #ececec;
      color: black;
      padding-left: 33px;
  }

  section {
    flex: auto 1 1;
    display: flex;
    align-items: stretch;

    > div {
      flex: auto 1 1;
      overflow-y: auto;
    }
  }

}

我的外部容器“.full”占据了屏幕的整个宽度和高度,并使用 display:flex 来确保标题 + 部分子项拉伸(stretch)以占据它们下方的所有空间。

现在,我想要的自然是标题占用 78px,部分占用 {full height - 78px} -- 但最好不要执行 calc 之类的操作。我希望能够在子部分的 div 中滚动,而不会影响其他 div 或整个页面。

这在 Chrome 中完美运行,但在 firefox、edge 或 ie 中打开我的 fiddle ,它没有按预期运行。 Section 获取 {lots and lots of content} 的高度,而不是只占用 '.full' 的剩余空间

我应该怎么做才能实现我期望的类似 Chrome 的布局?

最佳答案

同时为您的部分应用overflow-y:auto,这将解决 IE 和 Firefox 中的问题。

section {
  flex: auto 1 1;
  display: flex;
  align-items: stretch;
  overflow-y: auto;

  > div {
    flex: auto 1 1;
    overflow-y: auto;
  }
}

Fiddle DEMO

关于html - 显示 :flex and scrolling inner divs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49553372/

相关文章:

html - 如何禁用IE中的文件输入文本框?

javascript - 如何停止鼠标垂直滚动

javascript - 通过 JavaScript 访问 CSS 文件内容

html - 嵌套 DIV - 4 个 div(正方形),其中 1 个有 4 个 div(正方形),其中 1 个有 4 个 div(正方形)

html - flex-grow 在列布局中不起作用

javascript - 调整隐藏框架的大小

html - 多类改变颜色

javascript - 使用 jquery 在单击按钮时加载 html 文件时遇到困难

javascript - CSS/JS 图标变形

html - 为什么当我使用 flex-direction 时我的 div 消失了?