主要记住以下3点:
第一点要求:position:absolute
第二点要求:left:50%;top:50%
第三点要求:margin-left::-(divWidth/2); margin-top:-(divHeight/2)
原理:
先让这个DIV绝对定位;
让他距离上边50%,左边50%;这会这个DIV的左上角这个点就是窗口的正中间;
再从这里点向左移动总宽及高的一半就可以了.
举例:
<style type="text/css">
<!--
div {
position: absolute;
top: 50%;
left: 50%;
height: 200px; margin-top: -100px;
width: 400px; margin-left: -200px;
}
-->
</style>
<div></div>