只是无法使用 bootstrap 或 vanilla flexbox 使 flex 垂直居中元素

Just cannot get flex to vertically center an element with bootstrap or vanilla flexbox

我在这里失去了理智。我已经浏览了我在 Whosebug 上找到的与我的问题相匹配的顶级 posts、flexbox 自己的资源和 bootstrap 的 tuts,我已经尝试自己实现这些。要么有一个我仍然缺少的基本 CSS 值(当然可能),要么有一个我仍然缺少的基本 flexbox 值,或者我完全误解了某些东西。我正在使用 Bootstrap 4 并且从未设法使用 flex.

使元素垂直居中

包含 Bootstrap 类 的我的标记内容显示在下方。 H1 元素沿 x 轴成功居中,但未沿 y 轴居中。

<section>
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="d-flex align-items-center justify-content-center">
                    <h1 class="neoretrodraw logo text-center">Logo Text Here</h1>
                </div>
            </div>
        </div>
    <div>
</section>

拜托,拜托,不要简单地指向同一网站上的另一个 post 或 posts - 我敏锐地意识到这个问题之前可能已经以不同的形式回答并且已经完成我的阅读。我觉得这是一件简单的事情,我错过了一个简单的错误。

您只需要在 flex class 中使用 class vh-100 以及 xy-axix 居中 h1

现场演示:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<section>
  <div class="container">
    <div class="row">
      <div class="col-12">
        <div class="vh-100 d-flex align-items-center justify-content-center">
          <h1 class="neoretrodraw logo text-center">Logo Text Here</h1>
        </div>
      </div>
    </div>
  </div>
</section>