Bootstrap 4 form design |
Bootstrap 4 provides the three types of form layouts,
- Default (Stacked) forms
- Form grid
- Inline forms
Default (Stacked) forms
Include a .form-group class to your form is the best way to wrap your desired form into some structure. It persuades ideal grouping of labels, help text, controls, validations etc..<form>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" placeholder="Enter Name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="Enter Email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="email" placeholder="Enter Password">
</div>
<button type="submit" class="btn btn-primary"><a href="https://primestudyhub.blogspot.com/search/label/Bootstrap%204" target="_blank">Submit</a></button>
</form>
The below example describes how to utilize stacked form in detail,Form grid
The form grid is used, when creating more complex forms like that require multiple columns, widths, and more alignment options. For example,<form> <div class="row"> <div class="col"> <input type="email" class="form-control" placeholder="Enter Email"> </div> <div class="col"> <input type="password" class="form-control" placeholder="Enter Password"> </div> <div class="col"> <button type="submit" class="btn btn-primary"><a href="https://primestudyhub.blogspot.com/search/label/Bootstrap%204" target="_blank">Submit</a></button> </div> </div> </form>
Form Row
The alternative of using .row class in form is .form-row, this helps in creating a complex ideal grid forms.<form> <div class="form-row"> <div class="col"> <input type="email" class="form-control" placeholder="Enter Email"> </div> <div class="col"> <input type="password" class="form-control" placeholder="Enter Password"> </div> <div class="col"> <button type="submit" class="btn btn-primary"><a href="https://primestudyhub.blogspot.com/search/label/Bootstrap%204" target="_blank">Submit</a></button> </div> </div> </form>You can use column sizing classes like .col-md-6, .col-md-3 etc.., to customize the forms.
Inline Forms
In order to display the controls, labels and button elements in a single horizontal row the .form-inline class can be used. This also supports the custom form controls and selects as well.<form class="form-inline"> <div class="input-group mb-2 mr-sm-2"> <div class="input-group-prepend"> <div class="input-group-text">Email</div> </div> <input type="email" class="form-control" id="Email" placeholder="Enter Email"> </div> <div class="input-group mb-2 mr-sm-2"> <div class="input-group-prepend"> <div class="input-group-text">Password</div> </div> <input type="password" class="form-control" id="Password" placeholder="Enter Password"> </div> <button type="submit" class="btn btn-primary mb-2"><a href="https://primestudyhub.blogspot.com/search/label/Bootstrap%204" target="_blank">Login</a></button> </form>
Comments