效果展示:

CSS——flex 垂直居中

父级元素:只需要设置justify-content和align-items属性为center即可

<div class="box">
    <p class="boxItem"></p>
 </div>
.box{
   width: 200px;
   height: 200px;
   border: solid 1px red;
   display: flex;
   justify-content: center;  //设置单元格内容的水平位置(左中右)
   align-items: center;   //设置单元格的垂直位置(上中下)
 }
 .boxItem{
   width: 50px;
  height: 50px;
   background: pink;
 }

相关文章:

  • 2022-01-17
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-08-05
  • 2021-04-23
相关资源
相似解决方案