【问题标题】:Vertical Center with Flexbox and alignment of child items [duplicate]带有Flexbox的垂直中心和子项的对齐方式[重复]
【发布时间】:2019-02-28 17:25:36
【问题描述】:

现在才开始尝试使用 flexbox,我正在使用它来垂直居中 div 内的内容。

    .parent{
       display: flex;
       align-items: center;
       justify-content: center;
    }
    <div class="parent">
       <h1>Title</h1>
       <p>Paragraph one.</p>
       <p>Paragraph two.</p>
    </div>

因此,当我这样做时,它可以工作,但子元素彼此并排放置,就像它们不再是块项目一样。我怎样才能让它们垂直居中但彼此堆叠?

干杯!

【问题讨论】:

  • 继续阅读flex-direction ...
  • @04FS 谢谢,flex-direction: column;做到了。

标签: css flexbox


【解决方案1】:

如果要在列中显示元素,则需要使用flex-direction: column 样式属性。

.parent{
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center;
}
<div class="parent">
   <h1>Title</h1>
   <p>Paragraph one.</p>
   <p>Paragraph two.</p>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-23
    • 2018-04-21
    • 2019-08-09
    • 2016-06-03
    • 2015-03-07
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    相关资源
    最近更新 更多