CSS水平垂直居中布局

1 inline-block+text-align+table-cell+vertical-align

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

2 absolute+transform

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

3 flex+justify-content+align-items

.parent{
    display: flex;
    justify-content: center;
    align-items:center;
}    

你可能感兴趣的:(CSS水平垂直居中布局)