css子元素水平垂直居中


两个元素父与子(父标签只有一个子标签)的情况下

方法一:(flex 双轴线居中对齐)

父标签样式

{

 display: flex; 

 justify-content: center;

 align-items: center;

}
flex 双轴线居中右键检查

 display:flex会自动把子级装换为块级元素

方法二:(定位自适应)

父标签

{
 position: relative
}

子标签

{

  position: absolute;

  top: 0; 

  left: 0;

  right: 0; 

  bottom: 0;

  margin: auto;

}
定位居中右键检查

 需要子级有固定宽高