left:50%;
margin-left:-子盒子(子绝父相)宽度的一半
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
}
body{
font-size: 14px;
}
ul{
list-style: none;
}
a{
text-decoration: none;
}
input{
border: 0;
outline: 0;
}
.father{
width: 100%;
height: 200px;
background-color: red;
position: relative;
}
.son{
width: 400px;
height: 100px;
background-color: blue;
position: absolute;
left: 50%;
margin-left: -200px;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>