简体   繁体   English

Flex v43中最大高度的Flex盒子错误

[英]Flex box bug with max-height in chrome v43

I have the following construct to render a simple layout with fixed header and footer and a flexible body that with scrollable content: http://jsbin.com/jokevuyave/1/edit?html,css 我有以下构造来呈现具有固定页眉和页脚的简单布局以及具有可滚动内容的灵活主体: http//jsbin.com/jokevuyave/1/edit?html,css

<div id="main-view">
  <div class="rows">
    <div class="head">header</div>
    <div class="main scroll"></div>
    <div>footer</div>
  </div>
</div>

and this are the styles: 这是风格:

.rows,
.columns {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.columns {
  flex-direction: row;
  max-height: 100%;
  overflow: hidden;
}

.main {
  flex: 1;
}

.scroll {
  display: flex;
  overflow: hidden;
  position: relative;
  flex-direction: column;
}

.scroll > * {
  margin: 0;
  width: 100%;
  overflow: auto;
}


html,
body,
#main-container,
#main-view,
.scrollable {
  height: 100%;
  margin: 0
}

#main-view > div {
  max-height: 100%;
  display: flex;
}

.head {
  height: 120px
}

This construct works well in firefox and also in chrome until the version 43 was released. 这个结构在firefox和chrome中运行良好,直到版本43发布。 Now the height of the containers is wrong, header and footer don't expand to display its content and the content container lays over the header content. 现在容器的高度是错误的,页眉和页脚不会展开以显示其内容,而内容容器会覆盖标题内容。 Any idea how to fix this? 知道如何解决这个问题吗?

Edit 编辑

The problem seems to be this line: 问题似乎是这一行:

#main-view > div {
  max-height: 100%;
}

The idea is that the box should only expand if the content is to large. 我们的想法是,只有在内容很大的情况下,框才会展开。

Change it to 将其更改为

#main-view > div {
  height: 100%;
}

fix the wrong height for the inner container but now the box has always the height of 100%, even if the content is really small. 修复内部容器的错误高度,但现在盒子的高度始终为100%,即使内容非常小。

There is a problem with max-heigth and flexbox: flexbox misbehaving with max-height max-heigth heigth和flexbox存在问题: flexbox行为与max-height行为不当

So the solution is to set the flex property to every element insight rows container to 0 因此解决方案是将flex属性设置为每个元素洞察rows容器为0

.rows .main {
  flex: 1;
}

.rows > * {
  flex: 0 0 auto
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM