我們經常用margin:0 auto來實作水準居中,而一直認為margin:auto不能實作垂直居中,實際上,實作垂直居中僅需要聲明元素高度和下面的CSS:
.Absolute-Center {
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
width:600px;
height:400px;
}
我們經常用margin:0 auto來實作水準居中,而一直認為margin:auto不能實作垂直居中,實際上,實作垂直居中僅需要聲明元素高度和下面的CSS:
.Absolute-Center {
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
width:600px;
height:400px;
}