简体   繁体   English

Chrome上的Flexbox最大高度解释更改

[英]Flexbox max-height interpretation change on Chrome

I have some code which currently renders properly on Chrome Stable. 我有一些代码,目前正在Chrome Stable上正确呈现。 I have received reports of the code working incorrectly on Beta and Dev and I am able to reproduce the issue on Canary. 我收到有关代码在Beta和Dev上运行不正确的报告,我能够重现Canary上的问题。 I found this PSA which appears related to my issue. 我发现这个PSA似乎与我的问题有关。 So, I am working under the assumption this is a change to more closely follow spec rather than a bug. 所以,我正在假设这是一个更严格遵循规范而不是错误的变化。

My software only targets Google Chrome. 我的软件仅定位到Google Chrome。 So, a robust solution is not necessarily needed although it would be nice to have backwards compatibility. 因此,不一定需要强大的解决方案,尽管向后兼容性会很好。

The setup is: 设置是:

  • Parent element has display:flex , flex-direction: column and has max-height applied to it. 父元素有display:flexflex-direction: column并且应用了max-height
  • A deep descendant of the parent exceeds the max-height 父级的深层后代超过了max-height

And the behavior change is: 行为改变是:

  • On stable, max-height is enforced and child does not break out. 在稳定的情况下,强制执行max-height ,并且孩子不会爆发。
  • On canary, max-height is disregarded and child breaks out. 在金丝雀上, max-height被忽视,孩子爆发。

I am able to prevent the child from breaking out by applying max-height to the inner element. 我可以通过将max-height应用于inner元素来防止孩子爆发。 However, this is not desirable because I would need to reduce the value for max-height by the height of footer which isn't easily done in a non-contrived example. 然而,这是不可取的,因为我需要通过footer的高度来减小max-height的值,这在非人为的例子中是不容易的。

The following code snippet highlights my issue: 以下代码段突出显示了我的问题:

 .outer { display: flex; flex-direction: column; max-height: 410px; } .inner { display: flex; flex-direction: column; } .content { width: 200px; height: 500px; background-color: green; } .footer { height: 20px; width: 200px; background-color: red; } 
 <div class='outer'> <div class='inner'> <div class='content'> </div> </div> <div class='footer'> </div> </div> 

Here is a screenshot of how this renders on Chrome Canary (left) vs Chrome Stable (right): 以下是Chrome Canary(左)与Chrome Stable(右)的渲染截图:

在此输入图像描述

Is anyone able to tell me how to adjust this code such that inner + footer respect the max-height value of outer ? 是否有人能够告诉我如何调整此代码,使inner + footer尊重outermax-height值?

I believe I understand the issue, but I will build upon this answer more as I learn more about the solution. 我相信我理解这个问题,但是当我对解决方案有更多了解时,我会更多地依据这个答案。

This issue was introduced due to resolution of this bug filed against Chromium . 由于解决了针对Chromium此错误,因此引入了此问题。 The spec indicates that the default value of a flex container should be min-height: auto where as currently it is min-height: 0 . 规范表明flex容器的默认值应为min-height: auto ,其中当前为min-height: 0

A specific comment addresses the fact that this is a breaking change against all production websites and references a suggested change: 一个具体的评论解决了这一事实,即这是对所有生产网站的重大变化,并引用了建议的更改:

The change is: 变化是:

In case this patch breaks any website or chrome UI, the fix is likely to add: 如果此修补程序破坏任何网站或chrome UI,修复程序可能会添加:

min-width: 0; min-width:0;

min-height: 0; 最小高度:0;

Applying min-height: 0 to .inner resulted in a layout consistent with what I currently see on stable. 应用min-height: 0.inner导致布局与我目前在stable上看到的一致。

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

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