未知元素的宽高情况下  垂直居中和水平居中

第一种 flex盒布局 (推荐)

/*弹性盒模型*/
/*主轴居中对齐*/
/*侧轴居中对齐*/
.ele{
display:flex;
justify-content: center;
align-items: center;
} 

 

第二种 css3的transform

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

 

第三种 display的table-cell  表格单元格

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

 

 

 

 

.

相关文章:

  • 2022-12-23
  • 2021-05-20
  • 2021-12-06
  • 2022-01-13
  • 2022-12-23
  • 2021-07-26
  • 2022-02-19
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案