html - 垂直居中对齐 Bootstrap 4 Form-Group Row

标签 html css twitter-bootstrap bootstrap-4

我有一个看起来像这样的表单:

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal card card-body my-bg">

        <div class="form-group row justify-content-center align-content-center">
            <div class="col-md">
                @Html.Label("My Label", new { @class = "control-label col-md-12" })
                <div class="col-md-12">
                    @Html.TextBoxFor(model => model.TestName, null, new { @class = "form-control", @disabled = "disabled" })
                </div>
            </div>
            <div class="col-md">
                @Html.Label("Label Two", new { @class = "control-label col-md-12" })
                <div class="col-md-12">
                    @Html.TextBoxFor(model => model.TestProperty, null, new { @class = "form-control", @disabled = "disabled" })
                </div>
            </div>
        </div>
    </div>
}

如您所见,我已经尝试过 justify-content-center align-content-center,但它们并没有使我的表单垂直居中。

如何使表单垂直居中?

最佳答案

垂直中心相对于容器的高度,在这种情况下容器 (.card) 没有定义的高度。

卡片一个高度,使用justify-content-center让卡片内容垂直居中...

https://www.codeply.com/go/FdHqOtS3Av

.card {
    min-height: 300px;
}

关于html - 垂直居中对齐 Bootstrap 4 Form-Group Row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48547984/

相关文章:

javascript - 使用 Javascript 将 URL 转换为可点击的链接

html - 影响文本颜色的透明背景

javascript - 当用户选择文件-> 打印时仅打印 iframe 的内容

html - IE7 css 帮助,为什么我的跨度不与我的内联图像垂直对齐?

javascript - 2个独立的下拉按钮

html - 在导航栏上均匀分布搜索表单

asp.net - 在 ASP.NET 中卡住 GridView header ?

html - Internet Explorer 不会使用@font-face 显示字体图标

html - 将行放在容器底部

jquery - 显示 :none; elements are hazy and floating right with bootstrap