<style>
.father{
height:300px;
width:500px;
position:relative;
background-color: pink;
}
.son{
width:100px;
height:100px;
position:absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin:auto;
background-color: aqua;
}
</style>
<style>
.father{
width:500px;
height: 400px;
position:relative;
background-color: pink;
}
.son{
width: 100px;
height:100px;
position:absolute;
background: aqua;
left: 50%;
top:50%;
margin-left:-50px;
margin-top: -50px;
}
</style>
<style>
.father{
width: 500px;
height: 400px;
position:relative;
background-color: pink;
}
.son{
width: 100px;
height: 100px;
background-color: green;
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
}
</style>
<style>
.father{
width: 500px;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
background-color: pink;
}
.son{
width: 100px;
height: 100px;
background-color: aqua;
}
</style>
垂直居中
最新推荐文章于 2022-03-25 16:53:37 发布