I have a very simple form with Bootstrap 3 which I can easily (automatically) align when I don't use input-group-addon
s.
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/
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 .
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.
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.
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
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