1. 使用Flexbox布局
.container {
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
}
  1. 使用绝对定位
.parent {
  position: relative;
}
.child {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}
  1. 使用table-cell布局
.container {
  display: table-cell;
  vertical-align: middle; /* 垂直居中 */
  text-align: center; /* 水平居中 */
}
css实现页面垂直居中

原文地址: http://www.cveoy.top/t/topic/dhO1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录