Skip to content Skip to sidebar Skip to footer

Twitter Bootstrap 3 Inline Form With Labels

After searching everywhere i couldnt see exactly how i can design an inline form that has the following design: (using bootstrap 3 classes instead of css customizations when possib

Solution 1:

Option #1 : fixed columns

You can use a structure mixing col-xs-12, col-sm-6 and col-lg-3 to get 1, 2 or 4 columns. Inside your form-group, remember to fix label/input sizes with col-xs-4 and col-xs-8 :

<divclass="container"><formclass="form form-inline"role="form"><legend>Form legend</legend><divclass="form-group col-xs-12 col-sm-6 col-lg-3"><labelfor="InputFieldA"class="col-xs-4">Field A</label><divclass="col-xs-8"><inputtype="text"class="form-control"id="InputFieldA"placeholder="InputFieldA"></div></div><divclass="form-group col-xs-12 col-sm-6 col-lg-3"><labelfor="InputFieldB"class="col-xs-4">Field B</label><divclass="col-xs-8"><inputtype="text"class="form-control"id="InputFieldB"placeholder="InputFieldB"></div></div><divclass="form-group col-xs-12 col-sm-6 col-lg-3"><labelfor="InputFieldC"class="col-xs-4">Field C</label><divclass="col-xs-8"><inputtype="text"class="form-control"id="InputFieldC"placeholder="InputFieldC"></div></div><divclass="form-group col-xs-12 col-sm-6 col-lg-3"><buttontype="submit"class="btn btn-default col-xs-8 col-xs-offset-4">Submit Button</button></div></form></div>

You still need a few CSS :

// get a larger input, and align it with submit button.form-inline.form-group > div.col-xs-8 {
    padding-left: 0;
    padding-right: 0;
}
// vertical align label.form-inlinelabel {
    line-height: 34px;
}
// force inline control to fit container width
// http://getbootstrap.com/css/#forms-inline
.form-inline .form-control {
    width: 100%;
}
// Reset margin-bottom for our multiline form@media (min-width: 768px) {
  .form-inline.form-group {
    margin-bottom: 15px;
  }
}

You can add as many inputs as you want.

enter image description here

Bootply

Option #2 : fluid columns

To be able to not care of the number of fields per row, you can use this structure :

<divclass="container"><formclass="form form-inline form-multiline"role="form"><legend>Form legend</legend><divclass="form-group"><labelfor="InputFieldA">Field A</label><inputtype="text"class="form-control"id="InputFieldA"placeholder="InputFieldA"></div><divclass="form-group"><labelfor="InputFieldB">Very Long Label For Field B</label><inputtype="text"class="form-control"id="InputFieldB"placeholder="InputFieldB"></div><divclass="form-group"><labelfor="InputFieldC">F. C</label><inputtype="text"class="form-control"id="InputFieldC"placeholder="InputFieldC"></div><divclass="form-group"><labelfor="InputFieldD">Very Long Label For Field D</label><inputtype="text"class="form-control"id="InputFieldD"placeholder="InputFieldD"></div><divclass="form-group"><labelfor="InputFieldE">Very Long Label For Field E</label><inputtype="text"class="form-control"id="InputFieldE"placeholder="InputFieldE"></div><divclass="form-group"><labelfor="InputFieldF">Field F</label><inputtype="text"class="form-control"id="InputFieldF"placeholder="InputFieldF"></div><divclass="form-group"><buttontype="submit"class="btn btn-default">Submit Button</button></div></form></div>

And a few CSS lines to fix margins :

.form-multiline.form-group {
    margin-bottom: 15px;
    margin-right: 30px;
}
.form-multilinelabel,
.form-multiline.form-control {
    margin-right: 15px;
}

enter image description here

Bootply

Solution 2:

The same as option #1 from @zessx, but without overriding CSS. This one also aligns labels to the right to increase space between label-control pairs. Class "media" is there to add top margin without creating a custom class, but in general case it is better to have a custom one.

<divclass="form-horizontal"><legend>Form legend</legend><divclass="media col-xs-12 col-sm-6 col-lg-3"><labelfor="InputFieldA"class="control-label text-right col-xs-4">Field A</label><divclass="input-group col-xs-8"><inputtype="text"class="form-control"id="InputFieldA"placeholder="InputFieldA"></div></div><divclass="media col-xs-12 col-sm-6 col-lg-3"><labelfor="InputFieldB"class="control-label text-right col-xs-4">Field B</label><divclass="input-group col-xs-8"><inputtype="text"class="form-control"id="InputFieldB"placeholder="InputFieldB"></div></div><divclass="media col-xs-12 col-sm-6 col-lg-3"><labelfor="InputFieldC"class="control-label text-right col-xs-4">Field C</label><divclass="input-group col-xs-8"><inputtype="text"class="form-control"id="InputFieldC"placeholder="InputFieldC"></div></div><divclass="media col-xs-12 col-sm-6 col-lg-3"><buttontype="submit"class="btn btn-default col-xs-8 col-xs-offset-4">Submit Button</button></div></div>

Bootply

Solution 3:

I would propose something completely different, wrap the labels and fields inside inline divs:

<divstyle="display:inline-block"> 
  Label:input
</div>

This way, when they are about to break, they break in pairs, labels+inputs.

Solution 4:

Alright I played with the grid system and this is as close as I could get to your setup.

<divclass="container"><formrole="form"class="form-horizontal"><divclass="form-group col-sm-5"><labelfor="inputPassword"class="col-xs-4 control-label">Email</label><divclass="col-xs-8"><inputtype="password"class="form-control"id="inputPassword"placeholder="Password" /></div></div><divclass="form-group col-sm-5"><labelfor="inputPassword"class="col-xs-4 control-label">Password</label><divclass="col-xs-8"><inputtype="password"class="form-control"id="inputPassword"placeholder="Password" /></div></div><buttontype="submit"class="btn btn-default">Submit</button></form></div>

This has two fields only. You might want to change the col classes to fit your layout.

jsFiddle

Solution 5:

You can try below

Working here- http://www.bootply.com/117807

<divclass="container"><divclass="row"><divclass="col-md-4"><divclass="row"><divclass="col-md-4 col-xs-3 col-sm-4"><label>First Name</label></div><divclass="col-md-8 col-xs-9 col-sm-8"><inputtype="text"></div></div></div><divclass="col-md-4"><divclass="row"><divclass="col-md-4 col-xs-3 col-sm-4"><label>Last Name</label></div><divclass="col-md-8 col-xs-9 col-sm-8"><inputtype="text"></div></div></div><divclass="col-md-4"><divclass="row"><divclass="col-md-4 col-xs-3 col-sm-4"><label>Contact</label></div><divclass="col-md-8 col-xs-9 col-sm-8"><inputtype="text"></div></div></div></div></div>

Post a Comment for "Twitter Bootstrap 3 Inline Form With Labels"