块元素,且宽和高已知
<!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>
* {
margin: 0;
padding: 0;
}
html, body, .father {
width: 100%;
height: 100%;
}
.father {
position: relative;
}
.child {
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -150px;
width: 300px;
height: 300px;
background-color: lightblue;
}
</style>
</head>
<body>
<div class="father">
<div class="child"></div>
</div>
</body>
<