简体   繁体   English

Google Chrome浏览器中的Flex列和最大高度错误

[英]Flex column and max-height bug in Google Chrome

In Google Chrome , Safari and IE I am encountering an overflow issue with the flex content. Google ChromeSafariIE中 ,flex内容遇到溢出问题。

The issue I am sure is related to the way Chrome doesn't cascade the flex object to it's children. 我确定的问题与Chrome不会将flex对象级联到其子级的方式有关。

I believe the correct way to handle the flex objects would be to remove all height/width and max-height/max-width attributes and to use the flex attribute to determine the size limitations. 我相信处理flex对象的正确方法是删除所有height/widthmax-height/max-width属性,并使用flex属性确定大小限制。 eg: 例如:

display:
flex: 0 0 100px;

However as the flex object is orientated as a column I can't do this. 但是,因为flex对象被定向为column所以我不能这样做。 Additionally this "bug" only occurs when using an img. 此外,此“错误”仅在使用img时发生。 Replacing the img with a div causes flex to behave as expected. 用div替换img会导致flex行为符合预期。


EXAMPLE (View in Chrome) 示例(在Chrome中查看)

 span{ background:#4b0; } .Flx { display: flex; } .Child { display: flex; flex:1; align-items: center; justify-content: center; max-height: 100px; flex-direction: column; background-color: #aaa; } .Child img { max-height: 100%; background-color: #fb4a4a; } 
 <div class="Flx"> <div class="Child"> <span>TEXT</span> <img src="https://i.stack.imgur.com/440u9.png"> </div> </div> 

It appears that this occurs when using flex and percentages on img tags simply changing % to pixels resolved the issue: 似乎在img标签上使用flex和img时发生了这种情况,只需将%更改为像素即可解决此问题:

max-height: 100px;

 span{ background:#4b0; } .Flx { display: flex; flex:1; } .Child { display: flex; align-items: center; justify-content: center; flex-direction: column; background-color: #aaa; } .Wrap{ align-items: center; justify-content: center; background:#00d; } .Wrap img { max-height: 100px; max-width:100%; background-color: #fb4a4a; } 
 <div class="Flx"> <div class="Child"> <span>TEXT</span> <div class="Flx Wrap"> <img src="https://i.stack.imgur.com/440u9.png"> </div> </div> </div> 

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

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