我正在尝试让一张图片适应一个容器,同时保持其宽高比。根据方向,图像应该占据全高或全宽。我的解决方案在我测试的所有浏览器上都可以正常工作,但在IE11上不能正常工作(惊人的是在10和9中可以)。
在IE 11中,图片在右侧被裁剪。如果可能的话,我希望有一种纯CSS的方法,我不关心是否居中。
这里是JSFiddle链接: https://jsfiddle.net/wagad0u8/
<div class="owl-item" style="width: 465px;">
<a class="img-flux" href="page1.html">
<img alt="omg" src="http://placehold.it/1000x100">
</a>
</div>
<div class="owl-item" style="width: 465px;">
<a class="img-flux" href="page1.html">
<img alt="omg" src="http://placehold.it/400x780">
</a>
</div>
.img-flux img {
border: 0;
max-height: 100%;
max-width: 100%;
height: auto;
width: auto;
position: relative;
transition: all 0.3s;
margin: 0 auto;
float: none;
display: block;
vertical-align:middle;
}
#content-block *:last-child {
margin-bottom: 0px;
}
.owl-item, .owl-item .img-flux {
height: 100%;
}
.img-flux {
background-color: #ECECEC;
position: relative;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.owl-item{
float:left;
height:300px;
margin-bottom:50px;
}
flex: 0 0 auto
,正如错误报告中所提到的。感谢提供链接。 - Josh Harrison