1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Title</title>
6 <style>
7
8 .box{
9 width: 440px;
10 height: 500px;
11 background-color: #ccc;
12 overflow: hidden;
13 position: relative;
14 }
15 .son{
16 width: 200px;
17 height: 100px;
18 background-color: red;
19 margin: auto;
20 position: absolute;
21 /*定位:参照的是父容器*/
22 left: 50%;
23 top: 50%;
24 /*偏移:偏移中的百分比参照的是自身*/
25 /*定位加变化是解决居中垂直对齐问题的神器、*/
26 transform: translate(-50%,-50%);
27 }
28 </style>
29 </head>
30 <body>
31 <div class="box">
32 <div class="son"></div>
33 </div>
34
35 </body>
36 </html>
