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>

H5C3--transform实现任何元素居中对齐

 

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-12-29
  • 2022-01-23
  • 2021-11-30
猜你喜欢
  • 2022-02-26
  • 2021-12-14
  • 2022-12-23
  • 2021-05-27
  • 2022-01-02
  • 2021-09-27
  • 2021-11-12
相关资源
相似解决方案