<div class="parent">
<div class="child">哈哈哈</div>
</div>
1,absolute + transform :绝对定位 +转换
.parent{
position: relative;
background: pink;
width: 200px;
height: 200px;
margin: 0 auto;
}
.child{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: red;
}
2。inline-block + text-align + table-cell + certical-align (单元格方式)
.parent{
text-align: center;
display: table-cell;
vertical-align: middle;
background: pink;
width: 200px;
height: 200px;
margin: 0 auto;
}
.child{
display: inline-block;
background: red;
}
3.flex + justify-content + align-items ( 弹性模型)
.parent{
display: flex;
justify-content: center;
align-items: center;
background: pink;
width: 200px;
height: 200px;
margin: 0 auto;
}
.child{
background: red;
}