在 IE11 上的嵌套 flexbox 容器中保持图像纵横比

Tod*_*odd 5 html css google-chrome flexbox internet-explorer-11

我正在使用 flexbox 来显示一行块。每个块都使用 flexbox 来显示一列元素。其中一个元素是需要保持纵横比的图像。下面的代码是我的代码的简化版本,它说明了我正在尝试做的事情。

在 Chrome 中,图像缩放为 186px x 186px。在 IE11 中,它们显示 186px x 500px。我尝试将图像包装在另一个 div 中并将其高度和/或宽度设置为 100%,但对 Chrome 和 IE11 都不起作用。

section {
    max-width: 600px;
    margin: 0 auto;
}

.grid {
    display: flex;
    flex-wrap: wrap;
    margin-left: -20px;
    margin-top: 10px;
}

.block {
    margin: 0;
    flex: 1 0 150px;
    margin-left: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.block img {
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<section>
    <div class="grid">
        <div class="block">
            <img src="http://placehold.it/500" alt="">
            <h2>Block title</h2>
        </div>
        <div class="block">
            <img src="http://placehold.it/500" alt="">
            <h2>Block title</h2>
        </div>
        <div class="block">
            <img src="http://placehold.it/500" alt="">
            <h2>Block title</h2>
        </div>
    </div>
</section>
Run Code Online (Sandbox Code Playgroud)

Tod*_*odd 10

看起来添加min-height: 1px;img是解决方案。我希望我有一个很好的解释为什么这行得通。这是我能找到的最好的

...我最好的猜测是 min-height 强制 IE 在所有调整大小后重新计算渲染内容的高度,这使得它意识到高度是不同的....