<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div {
width: 200px;
height: 200px;
background-color: blue;
/*transform: translate(100px); 水平移动100像素*/
/*transform: translate(50%); */ /*水平移动100像素 如果是%不是以父亲宽度为准,以自己的宽度为准*/
/*transform: translate(50%); 意思是 走div盒子 自己宽度200的一半 走100像素 与父亲无关!!!*/
/*让定位的盒子居中对齐*/
position: absolute;
left: 50%; /*以父级宽度为准*/
top: 50%;
/*margin-left: -100px; 缺点需要计算容易出bug,用transform: translate(); */
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<div></div>
</body>
</html>