面试遇到居中的问题,建议的答案

 

建议,position:absolute; top:0px; left:0px;bottom:0px;right:0px;

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>demo</title>
</head>
<body>
<style type="text/css">
.div1{ width: 100px; height: 100px; border: 1px solid #000000;}
.div2{ width:40px ; height: 40px; background-color: green;}

.div11{
position: relative;
}
.div22{
position: absolute;margin:auto; top: 0;left: 0;right: 0;bottom: 0;
}
</style>

<div class="div1 div11">
<div class="div2 div22">

</div>
</div>

</body>
</html>

posted @ 2017-12-26 19:45  琼琼Daring  阅读(162)  评论(0编辑  收藏  举报