Image height in flexbox not working in IE

拥有回忆 提交于 2019-12-05 16:52:40
Michael_B

height: auto simply means the height of the content. It's a default value; you don't need to specify it.

If you remove height: auto from your code, it doesn't change anything (in any browser).

From the spec: 10.5 Content height: the height property


The problem appears to be that margin: auto is respected in Chrome and FF. But it is being (mostly) ignored in IE 11/Edge.

This is probably a bug. IE11 in particular is known to have many flexbugs:


A simple cross-browser solution would be to use a margin: auto equivalent:

Instead of this code on the flex item:

img {
    margin: auto;
}

Use this on the flex container:

.grid-cell {
    display: flex;
    justify-content: center;
    align-items: center;
}

For more details see box #56 here: https://stackoverflow.com/a/33856609/3597276

Revised Fiddle

.grid-row {
  width: 300px;
  height: 300px;
  display: flex;
  margin: auto;
}
.grid-cell {
  height: 100%;
  width: 25%;
  transition: box-shadow 2s;
  display: flex;
  justify-content: center;    /* NEW */
  align-items: center;        /* NEW */
}
img {
  width: 60%;
  /* margin: auto; */
  /* height: auto !important; */
  min-height: 1px;
}
.long {
  width: 80%;
  /* height: auto !important; */
}
<div class="grid-row">
  <div class="grid-cell">
    <img class="long" src="http://placehold.it/350x500">
  </div>
  <div class="grid-cell">
    <img class="long" src="http://placehold.it/350x500">
  </div>
  <div class="grid-cell">
    <img class="long" src="http://placehold.it/350x500">
  </div>
  <div class="grid-cell">
    <img class="long" src="http://placehold.it/350x500">
  </div>
  <div class="grid-cell">
    <img class="long" src="http://placehold.it/350x500">
  </div>
</div>

try adding display: -ms-flexbox; for IE 10

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