【问题标题】:Align both vertically and horizontally using Bootstrap flex [duplicate]使用 Bootstrap flex 垂直和水平对齐 [重复]
【发布时间】:2020-04-02 11:16:54
【问题描述】:

查看 bootstrap 4 Flex 文档后,我似乎无法让“align-item-center”属性工作。我测试了几乎所有在线可用的示例,但似乎真的无法改变任何东西的垂直对齐方式,这让我发疯了。我加入了一个我正在尝试制作的简单 HTML 示例。

.d-flex {
  display: -ms-flexbox !important;
  display: flex !important;
}

.justify-content-center {
  -ms-flex-pack: center !important;
  justify-content: center !important;
}

.align-items-center {
  -ms-flex-align: center !important;
  align-items: center !important;
}
<div class="d-flex justify-content-center align-items-center">
  <p> This should be centered right ?</p>
</div>

我正在使用 Bootstrap 4.4.1 并且还安装了 popper.js@latest 和 jquery@latest 以确保。为了更精确,我现在只使用一个简单的文本行,但将来我会添加直到运行时才知道大小的元素。

【问题讨论】:

  • 这个以什么方式居中?
  • 它已经在工作了。尝试为父 div 指定高度并查看对齐方式。

标签: html css bootstrap-4 flexbox


【解决方案1】:

height 设置为屏幕大小的父级或任何你想要的我将它设置为视口高度的100%

.d-flex.justify-content-center.align-items-center {
    height: 100vh;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 2021-04-06
    • 2012-10-10
    • 2012-05-17
    • 2019-10-08
    • 2014-04-19
    相关资源
    最近更新 更多