简单的几种垂直居中方式
1. diplay: table
.parent{
display: table
}
.child{
display: table-cell;
vertical-align: middle
}
复制代码
2. display: flex
.box{
display: flex;
justify-content: center; // 主轴 flex-direction默认为row
align-items: center; // 辅轴
}
复制代码
3. position: relative
.box{
position: relative;
top: 50%;
left: 50%;
transform: tranlate(-50%, -50%);
}
复制代码
4. margin: auto
.box{
margin: auto 0;
}
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END