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

HTML

<div class='father'>
    <div class='child'></div>
</div>

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;
    }
posted @ 2019-08-20 19:54  Cry_boy  阅读(289)  评论(0编辑  收藏  举报