<!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>
*{
margin: 0;
padding: 0;
}
body{
height: 8000px;
}
div{
width: 300px;
height: 200px;
background-color: aqua;
position: absolute;
/*四则运算 支持+ - 运算符符号前后写空格 */
top: calc(50% - 100px);
left: calc(50% - 150px);
}
.box{
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top:50%;
margin-top: -50px;
left:50%;
margin-left: -50px;
}
.box2{
width: 80px;
height: 80px;
background-color: blueviolet;
margin: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<div>方法一</div>
<div class="box">方法二</div>
<div class="box2">方法三</div>
</body>
</html>