当前位置: 移动技术网 > IT编程>网页制作>CSS > 关于盒子的水平垂直居中几种方案

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

2019年08月21日  | 移动技术网IT编程  | 我要评论

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;
    }

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网