html结构
<div class="outside-container">
<div class="inner-container">需要水平、垂直居中的DIV</div>
</div>
CSS3样式
.outside-container {
background: rgba(0,0,0,.5);
position: fixed;
z-index: 9999;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* 居中内部div样式 */
display: -webkit-flex;
-webkit-justify-content: center;
-webkit-align-items: center;
}
.inner-container {
position: relative;
background-color: #FFF;
padding: 20px;
border-radius: 4px;
/* ... */
}
应用场景:弹窗提示、弹层loading等等