Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline Bootstrap form layout with labels above inputs

I'd like to create a form with the following layout using Bootstrap 3:

enter image description here

I have a jsfiddle with an attempt here: http://jsfiddle.net/quyB6/

And the markup I've tried:

<form>     <div class="form-group col-md-4">         <label for="name" class="control-label">Line Height</label>         <input type="number" value='' class="form-control" id="lineHeight">     </div>     <div class="form-group col-md-4">         <label for="name" class="control-label">Padding Top</label>         <input type="number" value='' class="form-control" id="paddingTop" />     </div>     <div class="form-group col-md-4">         <label for="name" class="control-label">Padding Bottom</label>         <input type="number" value='' class="form-control" id="paddingBottom">     </div> </div> 
like image 824
Chad Johnson Avatar asked Jun 28 '14 22:06

Chad Johnson


People also ask

How do you put input and label on the same line?

Using float and overflow attributes: Make a label and style it with float attribute. Now set the label float(position) left or right according to your requirement. This will align your label accordingly. Overflow property for input is used here to clip the overflow part and show the rest.

Are label tags inline?

There are no special styling considerations for <label> elements — structurally they are simple inline elements, and so can be styled in much the same way as a <span> or <a> element.

What are floating labels?

Floating labels display the type of input a field requires. Every Text Field and Select should have a label, except for full-width text fields, which use the input's placeholder attribute instead. Labels are aligned with the input line and always visible.

Should an input always have a label?

Not all inputs need labels An input with a type="submit" or type="button" does not need a label — the value attribute acts as the accessible label text instead. An input with type="hidden" is also fine without a label.


2 Answers

I think the simplest solution would be to add col-xs-4 to the class of each div. That will make sure the divs will be inline for the jsfiddle example. Additionally, you should close the form tag with </form>.

<form>     <div class="form-group col-xs-4 col-md-4">         <label for="name" class="control-label">Line Height</label>         <input type="email" value='' class="form-control" id="name" placeholder="Ime">     </div>     <div class="form-group col-xs-4 col-md-4">         <label for="name" class="control-label">Padding Top</label>         <input type="email" value='' class="form-control" id="name" placeholder="Ime">     </div>     <div class="form-group col-xs-4 col-md-4">         <label for="name" class="control-label">Padding Bottom</label>         <input type="email" value='' class="form-control" id="name" placeholder="Ime">     </div> </form> 
like image 95
nicholaschris Avatar answered Sep 19 '22 18:09

nicholaschris


For bootstrap v4 you can use d-flex flex-column:

<div class="form-group col-md-4">     <div class="d-flex flex-column">         <label for="name" class="control-label">Line Height</label>         <input type="number" value='' class="form-control" id="lineHeight">     </div> </div> 
like image 26
F.D.Castel Avatar answered Sep 20 '22 18:09

F.D.Castel