演示代码:
<!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: 50%;
height: 50%;
background-color: #ff0000;
position: absolute;
/* 定位加外边距自适应居中方法 */
top: 0;left: 0;/* top和left优先 */
bottom: 0;right: 0;
margin: auto;
}
</style>
</head>
<body>
<div id="box">
<div class="wyzx"></div>
</div>
</body>
</html>