CSS水平垂直居中布局

2016-08-31  本文已影响0人  wanghaoi

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;
}    
上一篇下一篇

猜你喜欢

热点阅读