让DIV在屏幕上下左右居中

转自:http://blog.sina.com.cn/s/blog_65d41dff0100v0iz.html

其实解决的思路是这样的:首们需要position:absolute;绝对定位。而层的定位点,使用外补丁margin负值的方法。负值的大小为层自身宽度高度除以二。

代码:

<style type="text/css">

<!--

#content{ width:402px;height:302px;position:absolute;top:50%;left:50%;margin:-151px 0 0 -201px;border:1px solid red;}

-->

</style>

<div id="content"></div>

posted on 2016-03-22 22:44  小豫  阅读(213)  评论(0编辑  收藏  举报

导航