方法1:line-height等于div的height

    1. div {
    2. width: 100px;
    3. height: 100px;
    4. line-height: 100px;
    5. text-align: center;
    6. }

    方法二:flex布局

    1. div {
    2. display: flex;
    3. justify-content: center;
    4. align-items: center;
    5. }