Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap label next to input

I'm trying to put an input field's label next to it instead of above it using bootstrap. Wrapping this in form-horizontal works, but it's not actually in a form (just an ajax call that reads the value). Is there a way to simply move the label to the left side of the input?

    <div class="controls-row">
        <div class="control-group">
            <label class="control-label" for="my-number">ALabel</label>

            <div class="controls">
                <input id="my-number" type="number"/>
            </div>
        </div>
    </div>    

The fiddle is at http://jsfiddle.net/7VmR9/

like image 242
Jeff Storey Avatar asked Jul 12 '13 21:07

Jeff Storey


People also ask

How do you keep your label and input 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.

How do I label a Bootstrap inline?

Displaying Bootstrap forms inline By default, form controls will be displayed one below the other. However, you can make your form labels and inputs appear inline, horizontally, by applying the form-inline class. (Note that it will appear inline only in viewports that are at least 576px wide.)

What is a floating label?

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.

How do you put a label inside a text field in HTML?

There are two ways to pair a label and an input. One is by wrapping the input in a label (implicit), and the other is by adding a for attribute to the label and an id to the input (explicit). Think of an implicit label as hugging an input, and an explicit label as standing next to an input and holding its hand.


2 Answers

Yes, you can do this by bootstrap column structure.

<div class="form-group">
  <label for="name" class="col-lg-4">Name:</label>
    <div class="col-lg-8">
      <input type="text" class="form-control" name="name" id="name">
    </div>
</div>

Here is a Bootply Demo

like image 133
Dhaval Ptl Avatar answered Sep 17 '22 14:09

Dhaval Ptl


The div is a block element, that means it will take as much width as it can and the input element is in it.

If you want the label to be next to the input element: either put the label in the div or make the div an inline-block element.

like image 20
zoran404 Avatar answered Sep 19 '22 14:09

zoran404