html - 在 Firefox 和 Chrome 48 中使用 flexbox 呈现问题

标签 html css scroll flexbox

<分区>

在 chrome 47 上(正确行为): 在 chrome 47 上,带有 .scroll 的 div 正在正确滚动,使用 flex 将高度设置为 100%。

在 firefox 上(错误行为): 在 Firefox 上,带有 .scroll 的 div 正在使用内容高度并且无法正确滚动。

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

http://jsfiddle.net/d4nkevee/

for (var i = 0; i < 100; i++)
  $(".scroll").append("Dynamic content<br>");
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;
}
<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>


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

最佳答案

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 */
}

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

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

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

4.5. Implied Minimum Size of Flex Items

To provide a more reasonable default minimum size for flex items, this specification introduces a new auto value as the initial value of the min-width and min-height properties defined in CSS 2.1. (read more)


更新

Chrome 似乎更新了它们的渲染行为。 Chrome 48 现在在最小 flex 大小方面模仿 Firefox。

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

关于html - 在 Firefox 和 Chrome 48 中使用 flexbox 呈现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35195876/

上一篇:javascript - 如何在三次单击 html5/javascript/css 时将表格单元格颜色更改为默认颜色

下一篇:html - 固定图片到底部

相关文章:

html - 在非 Leaflet 应用程序 (Sigma JS) 中重新创建放大/缩小按钮?

css:如果分辨率低于 1024 x 786,则在网站主背景图像的底部和右侧获取空白

html - 固定顶部导航太低

css - 向下滚动动画或触发 block

java - GWT OnScroll 事件不会触发

html - 我的网站不适合移动设备,只有 slider 没有响应,我想让 slider 响应,

html - CSS3 和 HTML 的隐藏特性/属性/属性/标签

javascript - 重定向到其他页面英特尔 XDK

javascript - 尝试将 CSS 转换与 jQuery Isotope 一起使用时出现问题

javascript - 如何在滚动时停止 CSS 动画?