如何让DIV水平和垂直居中

如题所述

第1个回答  2017-01-16
可以使用mardin 0 auto 先水平居中 在设置margin-top的值 使其水平居中


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
.main{
width:300px;
height:300px;
border: 3px solid red;
margin: auto; 
}
.test{
width:100px;
height:100px;
border: 3px solid red;
margin: auto; 
margin-top:100px;/*外框300/2-内框100/2*/
}
</style>
</head>
<body>
<div class="main">
<div class="test">
</div>
</div>
</body>
</html>