<div class="row justify-content-center">
<form id="register-form" action="/register" method="POST">
<div class="form-group">
<input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text">
<div class="alert alert-danger" role="alert">This username is taken</div>
</div>
<div class="form-group">
<input class="form-control" name="password" placeholder="Password" type="password">
</div>
<div class="form-group">
<input class="form-control" name="confirm-password" placeholder="Confirm Password" type="password">
</div>
<div class="form-group">
<button class="btn btn-block btn-primary" type="submit">Register</button>
</div>
</form>
</div>
我希望<div class="alert alert-danger" role="alert">This username is taken</div>
出现在for用户名旁边(右侧);警报是高度和宽度。
这可能吗?
答案 0 :(得分:0)
您需要重新布局。
.container-xl
。
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-xl">
<form class="row justify-content-center" id="register-form" action="/register" method="POST">
<div class="col-12 col-lg-6 offset-lg-4">
<div class="row form-group">
<div class="col-12 col-md-6">
<input autocomplete="off" autofocus class="form-control h-100" name="username" placeholder="Username" type="text">
</div>
<div class="col-12 col-md-6">
<div class="alert alert-danger py-0 h-100 d-flex align-items-center" role="alert">This username is taken</div>
</div>
</div>
<div class="row form-group">
<div class="col-12 col-md-6">
<input class="form-control" name="password" placeholder="Password" type="password">
</div>
<div class="col-12 col-md-6">
</div>
</div>
<div class="row form-group">
<div class="col-12 col-md-6">
<input class="form-control" name="confirm-password" placeholder="Confirm Password" type="password">
</div>
<div class="col-12 col-md-6"></div>
</div>
<div class="col-12 col-md-6 pl-md-0">
<button class="btn btn-block btn-primary" type="submit">Register</button>
</div>
</div>
</form>
</div>
https://getbootstrap.com/docs/4.0/layout/grid/#offsetting-columns