css 常用的绝对定位元素水平垂直居中的方法

两种方法都能够实现:

1.

div {  
  height:80%; /*一定要设置高度*/ 
 overflow:hidden;/*建议设置*/ margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0; }

2.

div{  
   position: absolute;  
    80%;  
   height: 60%;  
   padding: 2%;   
   top: 50%;
   left: 50%;  
   margin-left: -41%;  /* (width + padding)/2 */  
   margin-top: -31%;  /* (height + padding)/2 */  
}     

  

原文地址:https://www.cnblogs.com/lilelile/p/7591413.html