【发布时间】:2016-04-05 18:16:39
【问题描述】:
正如您在下面的演示中所见,margin: auto; 将蓝色 div 水平居中,但不是垂直居中。为什么不呢?
.box {
border: 1px solid red;
width: 100px;
height: 100px;
}
.center {
background: blue;
width: 50px;
height: 50px;
margin: auto;
}
<div class="box">
<div class="center"></div>
</div>
我的问题不是寻求解决方法。
【问题讨论】:
-
它只是没有。水平居中内容的用例可能比垂直居中更常见。
-
@TZHX 从技术上讲,它可以垂直居中。请参阅此示例 - jsfiddle.net/skdjhpo8
-
CSS 中的垂直对齐是一个神话
-
@FabioPoloni Flexbox?
-
@FabioPoloni ¯\_(ツ)_/¯ IE do actually support flexbox 的较新版本,有一些注意事项。