css实现的div垂直居中成效代码实例
css实现的div垂直居中效果代码实例
css实现的div垂直居中效果代码实例:
关于div垂直居中效果,在网上已经有很多介绍了。
本章节再来通过代码实例演示一下如何实现此效果,希望能够给需要的朋友带来帮助。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂蚁部落</title> <style type="text/css"> #box{ width:400px; height:200px; background:#CCC; position:relative; } #inner{ width:50px; height:50px; background:green; position:absolute; left:50%; top:50%; margin-left:-25px; margin-top:-25px; } </style> </head> <body> <div id="box"> <div id="inner"></div> </div> </body> </html>
上面的代码非常的简单,这里就不多介绍了,如有任何问题可以跟帖留言。
原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=16811
更多内容可以参阅:http://www.softwhy.com/divcss/