<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
/* 子绝父相 三种 */
.father {
width: 500px;
height: 500px;
background-color: yellowgreen;
position: relative;
}
/* 第一种 margin:auto; */
.son {
width: 300px;
height: 300px;
background-color: pink;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
/*第二种 margin手动回移 */
/* .son {
width: 300px;
height: 300px;
background-color: pink;
position: absolute;
top: 50%;
left: 50%;
自身宽度的一半
margin-left: -150px;
自身高度的一半
margin-top: -150px;
} */
/* 第三种 通过transform属性自动回移 */
/* .son {
width: 300px;
height: 300px;
background-color: pink;
position: absolute;
top: 50%;
left: 50%;
transform:translate(-50%,-50%)
} */
/*第四种 弹性布局 */
/* .father {
width: 500px;
height: 500px;
background-color: yellowgreen;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.son{
width: 300px;
height: 300px;
background-color: pink;
} */
/* 第五种 display:table-cell
只能用于行内元素或者行内块元素的居中 */
/* .father{
display: table-cell;
vertical-align: middle;
text-align: center;
}
.son{
display: inline-block;
width: 300px;
height: 300px;
background-color: pink;
} */
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>