<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/style.css"/>
<title></title>
</head>
<body>
<div id="content">
<div><div>居中</div></div>
</div>
</body>
</html>
#content>div{
width: 500px;
height: 400px;
background:green;
position: absolute;
top: 50%;
left: 50%;
margin-left: -250px;
margin-top: -200px;
}
#content>div>div{
background-color: red;
text-align: center;
width: 200px;
height: 200px;
line-height: 200px;
position: relative;
top: 50%;
left: 50%;
margin-left: -100px;
margin-top: -100px;
}