<div id="wrapper"> <div id="cell"> <p>测试垂直居中效果测试垂直居中效果</p> <p>测试垂直居中效果测试垂直居中效果</p> </div> </div>
css代码:
#wrapper {display:table;width:300px;height:300px;background:#000;margin:0 auto;color:red;} #cell{display:table-cell; vertical-align:middle;}
<div id="wrapper"> <div id="cell"> <p>测试垂直居中效果测试垂直居中效果</p> <p>测试垂直居中效果测试垂直居中效果</p> </div> </div>
css代码:
#wrapper {display:table;width:300px;height:300px;background:#000;margin:0 auto;color:red;} #cell{display:table-cell; vertical-align:middle;}