CSS | CSS中元素居中(垂直/水平)的设置方法

1. 块状元素居中(垂直+水平)
    法1:

1  position: absolute; /* 重点 */
2  top: 0;
3  right: 0;
4  bottom: 0;
5  left: 0;
6  margin: auto; 

    法2:

1  position: absolute; /* 重点 */
2  top: 50%;
3  left: 50%;
4  margin: -100px 0 0 -100px; /* margin-top和margin-left分别设置为容器盒子div高度、宽度的-50% */

2. 文字居中(垂直+水平)

1  text-align: center;
2  line-height: 200px;  /* 行高要设置得和容器盒子div的高度一样以保证垂直居中 */
原文地址:https://www.cnblogs.com/binaryguy/p/14622394.html