gpt4 book ai didi

html - CSS 居中和垂直对齐

转载 作者:技术小花猫 更新时间:2023-10-29 12:01:09 25 4
gpt4 key购买 nike

我已经使用 bootstrap material UI 构建了一个注册表单,我试图将此表单垂直和水平对齐到网页的中心。到目前为止,这是我的代码:

.row {
display: flex;
justify-content: center;
align-items: center;
}
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-lg-6">
<div class="well bs-component">
<form class="form-horizontal" name="signUp" id="signUp" novalidate>
<fieldset>
<legend>Sign Up</legend>
<div class="form-group inputEmail">
<label for="inputUsername" class="col-lg-2 control-label">Username</label>
<div class="col-lg-10">
<input type='email' class="form-control" id="inputEmail" placeholder="Your Email" maxlength="56" />
</div>
</div>
<div class="form-group inputPassword">
<label for="inputPassword" class="col-lg-2 control-label">Password</label>
<div class="col-lg-10">
<input type='password' class="form-control" id="inputPassword" placeholder="Your Password" minlength="6" />
</div>
</div>
<div class="form-group inputConfirmPassword">
<label for="inputConfirmPassword" class="col-lg-2 control-label">Confirm Password</label>
<div class="col-lg-10">
<input type='password' class="form-control" id="inputConfirmPassword" placeholder="Confirm your password" minlength="6" />
</div>
</div>
<div class="form-group inputFirstName">
<label for="inputFirstName" class="col-lg-2 control-label">First Name</label>
<div class="col-lg-10">
<input type='text' class="form-control" id="inputFirstName" placeholder="First Name" maxlength="50" />
</div>
</div>
<div class="form-group inputLastName">
<label for="inputLastName" class="col-lg-2 control-label">Last Name</label>
<div class="col-lg-10">
<input type='text' class="form-control" id="inputLastName" placeholder="Last Name" maxlength="50" />
</div>
</div>
<div class="form-group inputDOB">
<label for="date" class="col-lg-2 control-label">Birthday</label>
<div class="col-lg-10">
<input type='date' class="form-control" id="inputDOB" placeholder="mm/dd/yyyy" />
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>

我可以水平对齐但无法垂直对齐。

Here is a jsfiddle.

最佳答案

您需要将 height: 100% 添加到所有父元素,以实现整个页面内的垂直对齐。目前该行仅占内容高度,并根据内容高度垂直对齐。

html, body, .row {
height: 100%;
}
.row {
display:flex;
justify-content: center;
align-items: center;
}

Updated JSfiddle

关于html - CSS 居中和垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33030880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com