max-width not functioning correctly in flex-box on IE11

为君一笑 提交于 2020-01-24 21:53:16

问题


In IE11, if you define a width for a flex-box and a child img element has a max-width of 100%, it will not respect the max-width. Has anyone found a solution for this?

This works in IE10, Chrome, and Firefox but breaks for IE11:
http://jsfiddle.net/3ky60heq/

.container {
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  width: 500px;
  height: 125px;
}

.image1 {
  width: 100%;
}

.image2,
.image3 {
  max-width: 100%;
}
<div class='container'>
  <img class='image1' src="https://clagnut.com/sandbox/imagetests/wideimg.png">
</div>

<div class='container'>
  <img class='image2' src="https://clagnut.com/sandbox/imagetests/wideimg.png">
</div>

<div class='container'>
  <img class='image3' src="https://clagnut.com/sandbox/imagetests/smimg1.jpg">
</div>

I recognize this question has been asked before and has many different answers however every solution I found on StackOverflow or elsewhere either effectively forces the width of the image to 100% or breaks on other browsers.


回答1:


I think I have it figured out. If I set this style on the image:

flex-shrink: 0;

then it seems to work across the board.
http://jsfiddle.net/qgybon8q/2/



来源:https://stackoverflow.com/questions/42493626/max-width-not-functioning-correctly-in-flex-box-on-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!