如何让一个div在另一个div中绝对居中(水平+垂直)

html:

<html>
<head></head>
<body>
<div class="parent">
<div class="child"></div>
</div>
</body>
</html>

css:

<style>
.parent{
position:relative;
width:600px;
height:300px;
border:1px solid red;
}
.child{
position:absolute;
width:450px;
height:198px;
left:50%;
top:50%;
margin-left:-225px;
margin-top:-99px;
}
</style>


效果如下图:

原文地址:https://www.cnblogs.com/ecosu/p/4285923.html