css元素真对父元素上下居中
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> body{margin: 0;} .box{ width: 400px; height: 400px; border:1px solid red; display: table-cell; vertical-align: middle; } .item{ margin:0 auto; width:200px; background: green; } </style> </head> <body> <div class="box"> <div class="item">dddddddddd <p>hhhhhhh</p> </div> </div> </body> </html>