元素的水平垂直居中
1、利用table标签,自带的功能
<style>
.parent{
border: 1px solid red;
height: 500px
}
.child{
border: 1px solid black
}
</style>
<body>
<!-- -->
<table class="parent">
<tr>
<td class="child">
测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试
测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试 测试
</td>
</tr>
</table>
</body>
效果

2、 margin-left: -50px; margin-top: -50px
<style>
.parent{
position: relative;
background-color: yellow;
width: 500px;
height: 200px
}
.child{
width: 100px;
height: 100px;
background-color: #fff;
position:absolute;
top:50%;
left: 50%;
margin-left: -50px;
margin-top: -50px }
</style>
效果

3、 transform: translate(-50%,-50%)
<style>
.parent{
width: 500px;
height: 300px;
border: solid 1px red;
position: relative; }
.child{
width: 200px;
height: 100px;
border: 1px solid black;
position:absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%)
}
</style>
效果

4、 margin: auto;
<style>
.p{
width: 300px;
height: 200px;
border: 1px solid red;
position: relative;
}
.c{
width: 80px;
height: 40px;
background-color: #dedede;
position:absolute;
margin: auto;
top:0;
bottom:0;
left: 0;
right: 0
}
</style>效果

5、弹性盒
<style>
.p{
border: 1px solid red;
width: 400px;
height: 500px;
display: flex;
justify-content: center;
align-items: center
}
.c{
width: 100px;
height: 100px;
background-color: red;









