I want to align input with label, to button without label, using bootstrap v3 with default form (vertical, not horizontal layout of form).
Desired effect: http://screencast.com/t/b2uwBopW9rW
I managed to solve this by creating label with non-breaking space inside label, but I wonder if there is more clean, better way to achieve this effect.
Example on jsfiddle: https://jsfiddle.net/r6o5hysk/1/
<div class='container' style='width:200px; margin: 50px;'>
<div class="row">
<div class="col-xs-10">
<div class="form-group">
<label>
Name
<input type="text" class="form-control" />
</label>
</div>
</div>
<div class="col-xs-2">
<div class="form-group">
<label>
<div class="btn btn-danger">Remove</div>
</label>
</div>
</div>
</div>
</div>
Thank you for your time.
Add text-align: center in your CSS or text-center class to your parent element (probably to a row or container ).
By adding the ” text-center” class of Bootstrap 3 We can use the “text-center” class of bootstrap 3 for the center-alignment of an element. So in our td when we add “text-center” class, and then our table text goes to the center.
Give textual form controls like <input> s and <textarea> s an upgrade with custom styles, sizing, focus states, and more.
Adding margins is not the best idea. What if the label
font-size
changes? You'll need to adjust the margin
as well.
Make the button
to act as a block
.btn.btn-as-block {
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class='container'>
<div class="row">
<div class="col-xs-9">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" />
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<label> </label>
<div class="btn btn-danger btn-as-block">Remove</div>
</div>
</div>
</div>
</div>
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