<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 200px;
height: 200px;
background-color: green;
}
/* 实习盒子垂直与水平居中 */
/* 方法1 */
/* div {
position: absolute;
left: 50%;
top: 50%;
/* transform: translate3d(-50%, -50%, 0); */
/* 按照盒子自身高度向左,向上移动50% */
/* transform: translate(-50%, -50%);
} */
/* 方法2 */
/* div {
position: absolute;
left: 50%;
top: 50%;
margin-top: -100px;
margin-left: -100px;
}
*/
/*方法3*/
div {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 200px;
height: 200px;
margin: auto;
background-color: green;
}
</style>
</head>
<body>
<div></div>
</body>
</html>