Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align inputs in bootstrap form with input-group-addons?

I have a very simple form with Bootstrap 3 which I can easily (automatically) align when I don't use input-group-addons.

After I use them in my form it is impossible to align it (the line with addons is wider because of added addons)

<form class="form-horizontal" role="form">      <div class="form-group">       <label for="product_name" class="col-sm-2 control-label">Product name</label>       <div class="col-sm-4">         <input type="text" class="form-control" id="product_name" placeholder="Product name">       </div>     </div>      <div class="form-group">       <label for="product_price" class="col-sm-2 control-label">Price</label>       <div class="col-sm-4 input-group">         <span class="input-group-addon">$</span>         <input type="text" class="form-control bfh-number" id="product_price" placeholder="Price" data-min="0" data-max="9999999">         <span class="input-group-addon">.00</span>       </div>     </div>      <div class="form-group">       <label for="product_description" class="col-sm-2 control-label">Description</label>       <div class="col-sm-6">         <textarea class="form-control" id="product_description" placeholder="Description" rows="5"></textarea>       </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> 

JsFiddle: http://jsfiddle.net/Yzxy3/

like image 879
Patryk Avatar asked Jan 24 '14 18:01

Patryk


People also ask

How do I center a bootstrap input box?

You can use offsets to make a column appear centered, just use an offset equal to half of the remaining size of the row, in your case I would suggest using col-lg-4 with col-lg-offset-4 , that's (12-4)/2 .

How do I change the input-group width in bootstrap?

Change the size of the input groups, by adding the relative form sizing classes like . input-group-lg, input-group-sm, input-group-xs to the . input-group itself.

What does input-Group do in bootstrap?

Bootstrap 4 Input Groups input-group class is a container to enhance an input by adding an icon, text or a button in front or behind the input field as a "help text". Use . input-group-prepend to add the help text in front of the input, and . input-group-append to add it behind the input.


1 Answers

Bootstrap documentation for input groups says :

Don't mix input-group with other components. (see:http://getbootstrap.com/components/#input-groups)

Do not mix form groups or grid column classes directly with input groups. Instead, nest the input group inside of the form group or grid-related element."

So you can't mix "col-sm-4" with "input-group" in the same class. You have to create 2 div class, the first with "col-sm-4" and the other with "input-group"

<div class="col-sm-4">   <div class="input-group">     <span class="input-group-addon">$</span>     <input type="text" class="form-control bfh-number" id="product_price" placeholder="Price" data-min="0" data-max="9999999">     <span class="input-group-addon">.00</span>   </div> </div> 

Updated Fiddle

like image 67
danivek Avatar answered Sep 20 '22 23:09

danivek