<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>不知道宽度和高是多少,实现水平垂直居中</title> <style> .div{ padding: 10px; border-radius: 10px; background: #776c6c; color: #fff; position: absolute; top:50%; left: 50%; -webkit-transform:translate(-50%,-50%); -moz-transform:translate(-50%,-50%); -transform:translate(-50%,-50%); } </style> </head> <body> <div class="div">不知道宽度和高是多少,实现水平垂直居中</div> 注意:手机端iphone 5有兼容性问题 </body> </html>