在Firefox和Chrome中使用flexbox渲染问题48

Ric*_*ard 7 html css scroll css3 flexbox

在chrome 47上(正确的行为): 在chrome 47上,div与.scroll正确滚动,使用flex取高度100%.

在Firefox上(错误的行为): 在Firefox上,该div .scroll使用内容高度而不是正确滚动.

什么是这个问题的跨浏览器解决方案?

http://jsfiddle.net/d4nkevee/

for (var i = 0; i < 100; i++)
  $(".scroll").append("Dynamic content<br>");
Run Code Online (Sandbox Code Playgroud)
body,
html {
  margin: 0;
  padding: 0;
}
.container {
  box-sizing: border-box;
  position: absolute;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.content {
  background: yellow;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.scroll {
  flex: 1 1 auto;
  overflow: scroll;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  
  <div class="bar">Small</div>
  
  <div class="content">
    
    <div>Static content</div>
    <div class="scroll"></div>
    <div>Static content</div>
    
  </div>
  
  <div class="footer">Small</div>
  
</div>
Run Code Online (Sandbox Code Playgroud)


问题已更新,以区分Chrome 47和Chrome 48.

Mic*_*l_B 14

更新了flexbox规范,使flex项的默认最小大小等于内容的大小:min-width: auto/ min-height: auto.

您可以使用min-width: 0/ 覆盖此设置min-height: 0:

.content {
    background: yellow;
    flex: 1;
    display: flex;
    flex-direction: column;

    min-height: 0;           /* NEW */
    min-width: 0;            /* NEW */
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/d4nkevee/1/

错误报告:https://bugzilla.mozilla.org/show_bug.cgi? id = 1043520

以下是规范中的一些细节:

4.5.隐含的最小Flex项目大小

是提供一种用于柔性的项目进行更合理的默认最小大小,本说明书中引入了一个新auto值作为的初始值min-widthmin-height在CSS 2.1定义的属性.(了解更多)


UPDATE

Chrome似乎已更新其渲染行为.Chrome 48现在可以根据最小的弹性尺寸来模拟Firefox.

根据以下链接中的报告,上述解决方案也适用于Chrome 48.

  • 我知道这个社区会帮助我修复这个无法解释的错误。非常感谢。它在这里工作就像一个魅力! (2认同)
  • @LeonAdler,使用各种关键字在谷歌中进行深入搜索,然后,如有必要,请点击您找到的页面中的链接,直到您到达目的地(如果它存在)。成为人类网络爬虫 ;-) (2认同)