垂直居中:spa
父元素定高,子元素不定高code
.parent{ width:400px; height:400px; position:relative; } .child{ position: absolute; top: 50%; transform: translateY(-50%); }
看別人文檔,有說能夠經過orm
.child{ position: relative;
top: 50%; transform: translateY(-50%); }
後面再試
子元素定高:blog
.parent{ width:400px; height:400px; display:table; } .child{ width:100px; height:100px; display:table-cell; vertical-align:middle; }