Skip to content

Latest commit

 

History

History
53 lines (49 loc) · 656 Bytes

File metadata and controls

53 lines (49 loc) · 656 Bytes

布局

实现垂直水平居中

已知宽度高度 position: absolute

.wrapper{
  position: relative;
}
.box{
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  margin: auto;
}

未知宽度高度 transform

.wrapper{
  position: relative;
}
.box{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%)
}

定义高度 transform

.wrapper{
  display: flex;
  justify-content: center;
  align-items: center;
}
.box{
  height: 100px;
}

未知宽度高度 table

.wrapper{
  display: table;
}
.box{
  display: table-cell;
  vertical-align: middle;
}