关于盒子的水平垂直居中几种方案

HTML

CSS

第一种

    .father {
        display: table-cell;
        text-align: center;
        vertical-align: middle;
    }
    
    .child {
        display: inline-block;
    }

第二种

    .father {
        position: relative;
    }
    
    .child {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
    }

第三种

    .father {
        display: flex;
        justfy-content: center;
        align-items: center;
    }

转载于:https://www.cnblogs.com/skyRider/p/11385051.html

你可能感兴趣的:(关于盒子的水平垂直居中几种方案)