【发布时间】:2018-06-22 04:01:30
【问题描述】:
所以,我尝试使用 flexbox 将 2 个 div 垂直居中,它以所有主流浏览器为中心,但在 IE11 上无法正确居中。
对此进行搜索,我发现以最小高度居中 div 存在问题,但我没有使用它,所以我不知道有什么问题或缺失。
.container {
position: relative;
display: flex;
align-items: center;
}
img {
max-width: 100%;
}
.prev {
width: 40px;
height: 40px;
background: rgba(0,0,0,.8);
position: absolute;
left: 30px;
}
.next {
width: 40px;
height: 40px;
background: rgba(0,0,0,.8);
position: absolute;
right: 30px;
}
<div class="container">
<img src="https://www.w3schools.com/css/trolltunga.jpg">
<div class="prev"></div>
<div class="next"></div>
</div>
【问题讨论】:
-
当你对一个元素应用绝对定位时,你会将它从文档流中移除。当这个元素恰好是 flex 容器中的子元素时,您可以将其从 flex 布局中移除。简而言之:flex 容器的绝对定位子级忽略 flex 属性。
-
只使用CSS定位属性:stackoverflow.com/q/35871294/3597276
标签: html css internet-explorer flexbox