Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap form-group spacing

I would like to have some spacing between the controls. According to spec, it should be achieved using form-group class. However it is not working in my case.

http://jsfiddle.net/TLF4L/

<div class="col-xs-12 col-sm-12">     <form role="form">         <div class="form-group">             <div class="col-xs-3 text-right">             <label for="cpTitle">Title</label>             </div>             <div class="col-xs-9">                 <input type="text" class="form-control" placeholder="Title of the program" id="cpTitle" />             </div>         </div>         <div class="form-group">             <div class="col-xs-3 text-right">             <label for="cpDesc">Description</label>             </div>             <div class="col-xs-9">                 <textarea class="form-control" rows="3" placeholder="Description of the program" id="cpDesc"></textarea>             </div>         </div>         <div class="form-group">             <div class="col-xs-3 text-right">                 <label for="cpAddr">Program address</label>             </div>             <div class="col-xs-9">                 <input type="text" class="form-control" placeholder="Name of Facility" id="cpAddr" />                 <input type="text" class="form-control" placeholder="Street 1" />                 <input type="text" class="form-control" placeholder="Street 2" />                 <div class="col-xs-4">                     <input type="text" class="form-control" placeholder="State" />                 </div>                 <div class="col-xs-4">                     <input type="text" class="form-control" placeholder="City" />                 </div>                 <div class="col-xs-4">                     <input type="text" class="form-control" placeholder="Zip" />                 </div>             </div>         </div>     </form> </div> 
like image 227
Srik Avatar asked May 12 '14 16:05

Srik


People also ask

What is the difference between the form-group and form-control in bootstrap?

While form-group sets up the spacing between form elements, form-control sets the width of the form element to 100%, causing it to span the width of the form and resize with the window.

How do I customize Bootstrap form?

The customized form can be created by using Bootstrap 4 like checkbox, radio buttons, file inputs and more. Bootstrap simplifies the process of alignment and styling of web pages in many forms like label, input, field, textarea, button, checkbox, etc. Custom Checkbox: The . custom-control and .

What is form-Group bootstrap?

The .form-group class is the easiest way to add some structure to forms. It provides a flexible class that encourages proper grouping of labels, controls, optional help text, and form validation messaging. By default it only applies margin-bottom , but it picks up additional styles in .form-inline as needed.

What is spacing bootstrap?

Spacing Bootstrap includes a wide range of shorthand responsive margin, padding, and gap utility classes to modify an element’s appearance.

What are the standard rules for all three forms in Bootstrap?

Standard rules for all three form layouts: Wrap labels and form controls in <div class="form-group"> (needed for optimum spacing) Add class.form-control to all textual <input>, <textarea>, and <select> elements Bootstrap Vertical Form (default)

How to add spacing between labels and controls in a form?

Using form-group classes in your form will automatically add spacing for labels and controls (a type of form item). You can add the form-group class to your form by encasing each label and control in a div class with the form-group class: <div class ="form-group"> <!-- Bootstrap Label or Control code here --> </div>

What is the width of form-control in Bootstrap?

Form controls automatically receive some global styling with Bootstrap: All textual <input> , <textarea> , and <select> elements with class .form-control have a width of 100%. Bootstrap Form Layouts


2 Answers

http://jsfiddle.net/TLF4L/6/

Main issue is to make sure you set class "form-horizontal" on your form. For the program address fields, you could either set out a separate row for each or what I'd suggest is just adding a css for margin-bottom on each input field. Edited jsfiddle above

.margin-bottom { margin-bottom:15px;}    <div class="col-xs-12 col-sm-12"> <form role="form" class='form-horizontal'>     <div class="form-group">         <div class="col-xs-3 text-right">             <label for="cpTitle">Title</label>         </div>         <div class="col-xs-9">             <input type="text" class="form-control" placeholder="Title of the program" id="cpTitle" />         </div>     </div>     <div class="form-group">         <div class="col-xs-3 text-right">             <label for="cpDesc">Description</label>         </div>         <div class="col-xs-9">             <textarea class="form-control" rows="3" placeholder="Description of the program" id="cpDesc"></textarea>         </div>     </div>     <div class="form-group">         <div class="col-xs-3 text-right">             <label for="cpAddr">Program address</label>         </div>         <div class="col-xs-9">             <input type="text" class="form-control margin-bottom" placeholder="Name of Facility" id="cpAddr" />             <input type="text" class="form-control margin-bottom" placeholder="Street 1" />             <input type="text" class="form-control margin-bottom" placeholder="Street 2" />         </div>     </div>     <div class="form-group">         <div class="col-xs-3 text-right">&nbsp;</div>         <div class="col-xs-3">             <input type="text" class="form-control" placeholder="State" />         </div>         <div class="col-xs-3">             <input type="text" class="form-control" placeholder="City" />         </div>         <div class="col-xs-3">             <input type="text" class="form-control" placeholder="Zip" />         </div>     </div> </form> 

like image 108
Daniel Broughan Avatar answered Sep 23 '22 18:09

Daniel Broughan


I updated your fiddle, added a textarea class as well. Updated fiddle

You need to use CSS to set a margin bottom to your input fields

input[type=text], .txtarea{ margin-bottom: 10px;   } 
like image 35
DivineChef Avatar answered Sep 20 '22 18:09

DivineChef