嵌套的DIV水平垂直居中

这是一个很简单的Blog(第一次写博,感受一下)

首先,双DIV嵌套。

html:

1 <div class="div1">
2         <div class="div2"></div>
3 </div>

css:

 1 .div1 {
 2   width:1000px;
 3   height:500px;
 4   border:2px solid #000;
 5   position:relative;
 6 }
 7  .div2 {
 8     width:200px;
 9     height:200px;
10     margin: auto;  
11     position: absolute;  
12     top: 0; left: 0; bottom: 0; right: 0; 
13     background-color: red;
14 }

很简单。

posted @ 2017-05-20 00:41  Charles王志会  阅读(171)  评论(0)    收藏  举报