css水平垂直居中代码实例
分类:实例代码
本章节分享一段简单的代码实例,它使用css实现了水平垂直居中效果。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>水平垂直居中</title> <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="demo/CSS/img/logo.png" /><br /> 前端教程网欢迎您.... </div> </div> </div> </body> </html>
一线大厂高级前端编写,前端初中阶面试题,帮助初学者应聘,需要联系微信:javadudu