position:absolute;的DIV 如何居中

时间:2021-10-05 20:32:44

外层DIV{position:realtive}
内层DIV{positon:absolute;top:50%;left:50%;margin-top:-100px;margin-left:-150px;width:300px;height:200px;}

<div class="father">
    <div class="son">
    </div>
</div>
.father{ position:realtive; width:100%; height:100%; }
.son{ position: absolute; left: 50%; top: 50%; z-index: 1; width: 1200px; margin-left: -600px; height:600px; margin-top:-300px; }