通常在制作网站首页时需要使页面内容在水平和垂直方向上都居中。 表格布局时代常用的方法是内容之前添加换行。实际上通过CSS有更方便的办法。
这个方法出自creamu.com。 先来看看代码和效果吧。
<style> #warp { position: absolute; width:500px; height:200px; left:50%; top:50%; margin-left:-250px; margin-top:-100px; border: solid 3px red; } </style> <body> <div id=warp>Test</div> </body>

原理很简单:将left和top设置为50%来定位div到浏览器中央,再将margin-left和margin-top值设置为宽和高的一半, 使div居中显示。
http://tech.idv2.com/2007/07/22/center-div-horizontally-and-vertically-with-css/