一、如何让固定定位和决定定位居中对齐
首先让该定位盒子先达到父盒子的中间(left:50%),然后使用margin-right让他居中
直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father{
width: 500px;
height: 500px;
background-color: pink;
position: relative;
}
.child{
width: 100px;
height: 100px;
left: 50%;
margin-left: -50px;
position: absolute;
background-color: blue;
}
</style>
</head>
<body>
<div class="father">
<div class="child"></div>
</div>
</body>
</html>
效果图