css 元素垂直居中

通用

<div id="parent">
<div id="child">Content here</div>
</div>
#parent {display: table;}
#child {
display: table-cell;
vertical-align: middle;
}
/*低版本 IE fix bug*/
#child {
display: inline-block;
}

 

定位居中

<div id="parent">
<div id="child">Content here</div>
</div>
#parent {position: relative;}
#child {
position: absolute;
top: 0;
left: 0;
height: 0;
width: 0;
margin: auto;
}

 

posted @ 2017-08-25 07:13  蚂蚁Zz  阅读(115)  评论(0编辑  收藏  举报