CSS垂直居中小结

1、设置子元素:

{
  ...
  position :absolute;
  margin:auto;   
  top:0;
  right:0;
  bottom:0;
  left:0;       
}

2、设置子元素:(height必须是固定值)

{
      position: absolute;
      top:50%;
      margin-top: - (0.5height);
}

3、设置子元素:(只适用于情况比较简单的单行文本)

{
  height:n px;
  line-height: n px; 
}

4、box 布局

5、transform

{
     position: absolute;
     top: 50%;  
     transform:translateY(-50%);  
}

  

原文地址:https://www.cnblogs.com/JRliu/p/5940322.html