css设置元素在浏览器中垂直水平居中代码实例
分类:实例代码
本章节分享一段代码实例,它实现了将元素设置在浏览器垂直水平居中效果。
代码实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <style> * { margin: 0; padding: 0; } .box { background-color: #000; width: 200px; height: 200px; position: absolute; top: 50%; left: 50%; margin-left: -100px; margin-top: -100px; } </style> </head> <body> <div class="box"></div> </body> </html>