首页 > 解决方案 > 列内容垂直对齐 - Bootstrap 4

问题描述

我正在尝试在用户提交表单之前创建加载动画,然后通知他们它是否成功或是否有错误。我的问题是加载图标和文本没有垂直对齐它所在的 div 的中心(col)。我希望将它放在中心,以便我可以在一段时间后用表单提交的响应替换列内容(加载图标和文本)。我正在使用 Bootstrap 4,并且尝试了各种不同的代码,例如列上的align-items-centermy-auto无济于事。

<div class="container-fluid h-100 w-100 formSubmitLoad d-flex flex-column" id="loader">
    <div class="row justify-content-center align-items-center h-100" id="loadingIcon">
        <div class="col-11 col-md-6 text-center bg-primary h-75">
            <i class="fas fa-spinner fa-pulse fa-4x"></i>
            <h2 class="pt-4">Loading</h2>
        </div>

        <div class="col-11 col-md-6 text-center bg-primary h-75 d-none">
            <!-- Column content to replace above column-->
        </div>
    </div>
</div>
.formSubmitLoad {
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  overflow: auto;
  color: white;
  background-color: rgb(0, 0, 0);
  background-color: rgba(0, 0, 0, 0.9);
}

片段: 片段

标签: htmlcssbootstrap-4

解决方案


更新您的代码,如下所示:

.formSubmitLoad {
  color: white;
  background-color: rgba(0, 0, 0, 0.9);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" >
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
<div class="container-fluid h-100 w-100 formSubmitLoad position-fixed" id="loader">
    <div class="row h-100" id="loadingIcon">
        <div class="m-auto col-11 col-md-6 d-flex flex-column justify-content-center align-items-center bg-primary h-75">
            <i class="fas fa-spinner fa-pulse fa-4x"></i>
            <h2 class="pt-4">Loading</h2>
        </div>

        <div class="m-auto col-11 col-md-6 text-center bg-primary h-75 d-none">
            <!-- Column content to replace above column-->
        </div>
    </div>
</div>


推荐阅读