垂直居中的方式

简单的几种垂直居中方式

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
喜欢就支持一下吧
点赞0 分享