简体   繁体   English

IE 11:图像在flexbox中无法正确缩小

[英]IE 11: Image doesn't scale down correctly within flexbox

I'm trying to use flexbox to place two images in a column. 我正在尝试使用flexbox将两个图像放在一列中。 In this case, the width of the div container is smaller than the width of the image. 在这种情况下, width在div容器的比较小的width的图像。 In Chrome the image perfectly fits into the div container, but it doesn't in IE, and I don't know why. 在Chrome中,图像完全适合div容器,但它不在IE中,我不知道为什么。

 div.outer { width: 400px; display: flex; flex-direction: column; justify-content: space-around; } div.inner { width: 100%; border: 1px solid red; } img { width: 100%; height: auto; } 
 <div class="outer"> <div class="inner"> <img src="http://placehold.it/480x360"> </div> <div class="inner"> <img src="http://placehold.it/480x360"> </div> </div> 

https://jsfiddle.net/Yifei/16cpckqk/ https://jsfiddle.net/Yifei/16cpckqk/

This is what I've got in IE 11: 这就是我在IE 11中得到的:

IE11 seems to have some trouble with the initial value of the flex-shrink property . IE11似乎在flex-shrink属性的初始值上有些麻烦。 If you set it to zero (it is initially set to 1), it should work: 如果将其设置为零(最初设置为1),它应该工作:

 div.outer { width: 400px; display: flex; flex-direction: column; justify-content: space-around; } div.inner { flex-shrink: 0; width: 100%; border: 1px solid red; } img { width: 100%; height: auto; } 
 <div class="outer"> <div class="inner"> <img src="http://placehold.it/480x360"> </div> <div class="inner"> <img src="http://placehold.it/480x360"> </div> </div> 

The accepted solution destroyed my sticky footers in ie. 接受的解决方案在ie中破坏了我的粘性页脚。 So I solved this disturbing issue with the following non satisfying "only for ie JS"... . 所以我解决了这个令人不安的问题,以下不满意的“仅适用于JS”...... The px value instead the "height:auto" did the trick for me. px值代替“height:auto”为我做了诀窍。

 if(fuBrowser =='ie'){
  var img = $("#teaser img");
    img.each(function() {
    $( this ).css({height: $( this ).height()});
    });
  }

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

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