shihao905

css水平垂直居中(绝对定位居中)

使用绝对定位有个限制就是父集必须设置一个固定的高度。

首先HTML

1 <div id="box">
2     <div class="child"></div>
3 </div>    

CSS

 1 #box {
 2     position: relative;
 3     height: 500px;
 4     background: red;
 5 }
 6 .child {
 7     width: 100px;
 8     height: 100px;
 9     background: blue;
10     margin: auto;
11     position: absolute;
12     top: 0;
13     right: 0;
14     bottom: 0;
15     left: 0;
16 }

示例图:

分类:

技术点:

相关文章:

  • 2021-11-30
  • 2021-09-30
  • 2021-11-30
  • 2021-12-20
  • 2021-08-31
猜你喜欢
  • 2021-11-30
  • 2021-11-30
  • 2021-11-30
  • 2021-09-28
  • 2021-08-31
  • 2021-12-04
  • 2021-05-20
相关资源
相似解决方案