flex布局,垂直居中不了?

讲道理我在panel>*下设置侧轴居中,文字垂直方向就会居中啊,为什么没有垂直居中?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style>
*{
    padding: 0;
    margin:0;
}
.panels{
    display: flex;
    /*justify-content:center;*/
    justify-content:center;
    color:#fff;
    font-size: 24px;
    font-weight: 600;

}
.panel{
    height:100vh;
    flex:1;
    display: flex;
    flex-direction:column;
    justify-content:center;
    align-items:center;
    background: cover;
    background-position: center; 
}
.panel>*{
    flex:1;
    justify-content:center;
    align-items:center;
}

.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
.panel2 { background-image:url(https://source.unsplash.com/1CD3fd8kHnE/1500x1500); }
.panel3 { background-image:url(https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d); }
.panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); }
.panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); }
</style>
<body>
    <div class="panels">
    <div class="panel panel1">
      <p>Hey</p>
      <p>Let's</p>
      <p>Dance</p>
    </div>
    <div class="panel panel2">
      <p>Give</p>
      <p>Take</p>
      <p>Receive</p>
    </div>
    <div class="panel panel3">
      <p>Experience</p>
      <p>It</p>
      <p>Today</p>
    </div>
    <div class="panel panel4">
      <p>Give</p>
      <p>All</p>
      <p>You can</p>
    </div>
    <div class="panel panel5">
      <p>Life</p>
      <p>In</p>
      <p>Motion</p>
    </div>
  </div>
</body>
</html>
阅读 7k
1 个回答
.panel>*{
    /* flex:1;
    justify-content:center;
    align-items:center; */
}

把这里样式删掉

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题