CSS窗口垂直水平居中
分类:实例代码
CSS窗口垂直水平居中属于前端实例代码,有关更多实例代码大家可以查看。
本章节分享一段代码,它实现了窗口的垂直水平居中效果。
在这里没有考虑低版本浏览器的兼容问题,其实在不久的将来也不用考虑。
代码实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>犀牛前端部落</title> <style type="text/css"> * { margin: 0; padding: 0; } body { height: 1000px; } section { position: fixed; left: 0; top: 0; width: 100%; width: 100vw; height: 100%; height: 100vh; background: #000; text-align: center; line-height: 100vh; opacity: 0.6; } section > div { display: inline-block; width: 500px; height: 300px; background: blue; vertical-align: middle; } </style> </head> <body> <section> <div></div> </section> </body> </html>
CSS窗口垂直水平居中,这样的场景在实际项目中还是用的比较多的,关于CSS窗口垂直水平居中就介绍到这了。