I have a normal form (Twitter Bootstrap, not inline) but one input field has a button next to it (see pic below). All input fields have a label at the top.
What is the proper Bootstrap syntax (preferably without having to add my own CSS) to have an inline form group (input field and button next to it) with a label that’s not inline (i.e. sits above the input field)?
<form>
<div class="form-group">
<label for="mobile">Mobile</label>
<input type="text" class="form-control" />
</div>
<div class="row">
<div class="col-xs-8">
<div class="form-group">
<label for="coupon">Coupon</label> <!-- should behave like the other non-inlined form fields -->
<input type="text" class="form-control" />
</div>
</div>
<!-- should be inline aligned with the input field -->
<div class="col-xs-4">
<button class="btn btn-primary">Apply</button>
</div>
</div>
</form>
4
Answers
You can add a style
margin-top:24px
to the button. I assume this button will eventually have anid
or otherclass
to identify it when it’s clicked. From there create a selector in your style sheet and add it there, instead of inline like this example.<button style="margin-top:24px;" class="btn btn-primary">Apply</button>
here you have a jsfiddle if you are not looking to center it with margin. You can add another class to these divs so you don’t change the all default bootstrap style but this is just to show you how you can do it
Here’s a JSFiddle that may help: https://jsfiddle.net/DTcHh/23855/
I tried to achieve this by not setting any fixed margin so that you can adjust the button size freely.
So the alignment is done by using javascript as follows:
The number
15
is added since Bootstrap has a defaultmargin-bottom: 15px
for inputs.You could use the input-group class Bootstrap already provides.
Like this:
jsFiddle
CODE SNIPPET: