演示代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="reset.css"/>
<style type="text/css">
html,body{
height: 100%;
}
#box{
width: 50%;
height: 50%;
background-color: aqua;
position: relative;
}
.wyzx{
width: 300px;
height: 100px;
background-color: #ff0000;
position: absolute;
/* 定位+外边距居中法 */
left: 50%;
margin-left: -150px;
top: 50%;
margin-top: -50px;
}
</style>
</head>
<body>
<div id="box">
<div class="wyzx"></div>
</div>
</body>
</html>