https://github.com/yanhaijing/vertical-center <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>水平垂直居中</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <style > * { margin: 0; padding: 0; font-size: 14px; color: #FFF;-webkit-text-size-adjust:none } .container { display: table; /*主要代码*/ *position: relative; /*for ie67*/ background-color: #FF5E53; width: 800px; height: 200px; overflow: hidden; margin: 0 auto; } .content { vertical-align: middle; display: table-cell; text-align: center; /*主要代码*/ *position: absolute; *top: 50%; *left: 50%; /*for ie67*/ } .center { display: inline-block; /*主要代码*/ *display: inline; zoom: 1; *position: relative; *top: -50%; *left: -50%; /*for ie67*/ padding: 10px; border: 1px solid #fff;} </style> </head> <body> <div class="container"> <div class="content"> <div class="center"> <img src="http://static.ydcss.com/www/img/logo.png" /><br/> 啦啦啦,啦啦啦,我是卖报的小行家.... </div> </div> </div> </body> </html> 提示:你可以先修改部分代码再运行。 转载请注明:有爱前端 » 水平垂直居中 喜欢 (2)or分享 (0)