Bs Forms
Bootstrap Forms
Bootstrap's Default Settings
Form controls automatically have about global styling with Bootstrap:All textual
<input>
, <textarea>
, in addition to <select>
elements with shape .form-control
bring a width of 100%.Bootstrap Form Layouts
Bootstrap provides 3 types of shape layouts:- Vertical shape (this is default)
- Horizontal form
- Inline form
- Wrap labels in addition to shape controls inwards
<div class="form-group">
(needed for optimum spacing) - Add shape
.form-control
to all textual<input>
,<textarea>
, in addition to<select>
elements
Bootstrap Vertical Form (default)
Example
<form>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Bootstrap Inline Form
Note: This alone applies to forms inside viewports that are at to the lowest degree 768px wide!
Additional dominion for an inline form:
- Add shape
.form-inline
to the<form>
element
Example
<form class="form-inline">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
.sr-only
class:Example
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label class="sr-only" for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Bootstrap Horizontal Form
Additional rules for a horizontal form:
- Add shape
.form-horizontal
to the<form>
element - Add shape
.control-label
to all<label>
elements
The next instance creates a horizontal shape with ii input fields, 1 checkbox, in addition to 1 submit button.
Example
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" placeholder="Enter password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
Comments
Post a Comment