How to vertically align label and input in Bootstrap 3? I would like both the label and input on same line. I have played around with different classes and custom CSS but nothing seems to work.
The JSfiddle
<div class="form-group">
<div class="row">
<div class="col-xs-3">
<label for="class_type"><h2><span class=" label label-primary">Class Type</span></h2></label>
</div>
<div class="col-xs-2">
<select name="class_type" id="class_type" class=" form-control input-lg" style="width:200px" autocomplete="off">
<option >Economy</option>
<option >Premium Economy</option>
<option >Club World</option>
<option >First Class</option>
</select>
</div>
</div>
</div>
Since Bootstrap 4 . row is now display:flex you can simply use align-self-center on any column to vertically center it... or, use align-items-center on the entire . row to vertically center align all col-* in the row...
Another way to vertically center is to use my-auto . This will center the element within its container. For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column. Since Bootstrap 4 .
We specify the margin-bottom of our <div> element. Then, we set the display of the <label> element to "inline-block" and give a fixed width. After that, set the text-align property to "right", and the labels will be aligned with the inputs on the right side.
The bootstrap 3 docs for horizontal forms let you use the .form-horizontal
class to make your form labels and inputs vertically aligned. The structure for these forms is:
<form class="form-horizontal" role="form"> <div class="form-group"> <label for="input1" class="col-lg-2 control-label">Label1</label> <div class="col-lg-10"> <input type="text" class="form-control" id="input1" placeholder="Input1"> </div> </div> <div class="form-group"> <label for="input2" class="col-lg-2 control-label">Label2</label> <div class="col-lg-10"> <input type="password" class="form-control" id="input2" placeholder="Input2"> </div> </div> </form>
Therefore, your form should look like this:
<form class="form-horizontal" role="form"> <div class="form-group"> <div class="col-xs-3"> <label for="class_type"><h2><span class=" label label-primary">Class Type</span></h2></label> </div> <div class="col-xs-2"> <select id="class_type" class="form-control input-lg" autocomplete="off"> <option>Economy</option> <option>Premium Economy</option> <option>Club World</option> <option>First Class</option> </select> </div> </div> </form>
I'm sure you've found your answer by now, but for those who are still looking for an answer:
When input-lg is used, margins mismatch unless you use form-group-lg in addition to form-group class. Its example is in docs:
<form class="form-horizontal">
<div class="form-group form-group-lg">
<label class="col-sm-2 control-label" for="formGroupInputLarge">Large label</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="formGroupInputLarge" placeholder="Large input">
</div>
</div>
<div class="form-group form-group-sm">
<label class="col-sm-2 control-label" for="formGroupInputSmall">Small label</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="formGroupInputSmall" placeholder="Small input">
</div>
</div>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With