首页 > 其他 > 详细

实现已知或者未知宽度的垂直水平居中

时间:2018-11-21 14:53:25      阅读:180      评论:0      收藏:0      [点我收藏+]
.wraper {
position: relative;
.box {
position: absolute;
top: 50 %;
left: 50 %;
width: 100px;
height: 100px;
margin: -50px 0 0 - 50px;
}
}
// 2
.wraper {
position: relative;
.box {
position: absolute;
top: 50 %;
left: 50 %;
transform: translate(-50 %, -50 %);
}
}
// 3
.wraper {
.box {
display: flex;
justify-content: center;
align-items: center;
height: 100px;
}
}
// 4
.wraper {
display: table;
.box {
display: table-cell;
vertical-align: middle;
}
}

实现已知或者未知宽度的垂直水平居中

原文:https://www.cnblogs.com/Tony100/p/9994050.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!