1、flex布局
.father {
display: flex;
justify-content: center;
align-items: center;
}
这种方式兼容性不好
2、position + transform
.son {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
IE9以下不支持transform属性
3、table + table-cell
.father {
display: table;
}
.son {
display: table-cell;
vertical-align: middle;
text-align: center;
}
4、:before + display:inline-block
.father {
text-align: center;
}
.father::before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
.son {
display: inline-block;
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理