我有下面的代码。
我想强制将图像max-width
约束/调整为容器的width,并且高度是自由的。它适用于Chrome / Firefox,但不适用于IE11
.cimage {
-ms-flex-align: center;
align-items: center;
border: 1px solid red;
display: -ms-flexbox;
display: flex;
-ms-flex-negative: 0;
flex-shrink: 0;
-ms-flex-positive: 0;
flex-grow: 0;
-ms-flex-pack: center;
justify-content: center;
padding: .75rem;
width: 5.5rem;
}
.cimage img {
max-width: 100%;
min-width:1px;
}
<div class="cimage">
<a href="/">
<img src="https://via.placeholder.com/250x150">
</a>
</div>
IE屏幕截图:
答案 0 :(得分:1)
将flex: 1
或min-width: 1px
添加到 flex项目-a
元素中,也可以在IE11中进行修复。参见下面的演示:
.cimage {
-ms-flex-align: center;
align-items: center;
border: 1px solid red;
display: -ms-flexbox;
display: flex;
-ms-flex-negative: 0;
flex-shrink: 0;
-ms-flex-positive: 0;
flex-grow: 0;
-ms-flex-pack: center;
justify-content: center;
padding: .75rem;
width: 5.5rem;
}
.cimage img {
max-width: 100%;
min-width:1px;
}
.cimage a { /* ADDED */
flex: 1;
}
<div class="cimage">
<a href="/">
<img src="https://via.placeholder.com/250x150">
</a>
</div>