div实现水平垂直居中

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.divWrap{
width: 500px;
height: 800px;
background: red;
margin: 20px auto;
position: relative;
}

.div{
position: absolute;
width: 30%;
height: 30%;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: green;
}
</style>
</head>
<body>

<div class="divWrap">
<div class="div">

</div>
</div>
</body>
</html>

posted on 2018-12-24 17:50  刘二鹏  阅读(176)  评论(0编辑  收藏  举报