先看效果:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>div居于页面正中间</title>
<style type="text/css">
.parent {
width: 20rem;
height: 12.5rem;
border: 2px solid #000;
position: relative;
}
.child {
width: 4rem;
height: 4rem;
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
</style>
</head>
<body>
<div class="parent">
<div>
上面的
</div>
<div class="child">
12栋
</div>
</div>
</body>
</html>