Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an inline form with input-groups bootstrap

I'm trying to create a simple inline form using input groups to display icons before the inputs. As far as I'm aware of I'm following the documentation but the form doesn't display as expected. See this JSFiddle, it demonstrates the problem. I assumed it should be displayed like this (only with the icons prepended of course). How can this be solved?

My code:

<form class="form-inline" role="form">
    <div class="form-group">    
        <div class="input-group">                       
            <span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
            <input type="email" class="form-control" placeholder="Enter email"/>
        </div>
    </div>

    <div class="form-group">
        <div class="input-group">
            <span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
            <input type="password" class="form-control" placeholder="Choose password"/>
        </div>
    </div>                          

    <button type="submit" class="btn btn-default">Create account</button>
</form>
like image 742
Ben Fransen Avatar asked Jan 09 '14 19:01

Ben Fransen


People also ask

How do I create a form element inline in bootstrap?

To create a form where all of the elements are inline, left aligned and labels are alongside, add the class . form-inline to the <form> tag.

Which bootstrap 4 class is used to create inline form on a webpage?

Additional rule for an inline form: Add class .form-inline to the <form> element.

What is form-inline in bootstrap?

Bootstrap Inline Form In an inline form, all of the elements are inline, left-aligned, and the labels are alongside. Note: This only applies to forms within viewports that are at least 768px wide! Additional rule for an inline form: Add class . form-inline to the <form> element.

How do I create a horizontal form in bootstrap?

Horizontal formCreate horizontal forms with the grid by adding the .row class to form groups and using the .col-*-* classes to specify the width of your labels and controls. Be sure to add .col-form-label to your <label> s as well so they're vertically centered with their associated form controls.


2 Answers

This is known issue and will be fixed in Bootstrap v.3.2.0 according to this ship list.

Before that you can fix it your self like this:

.input-group {
    display: inline-table;
    vertical-align: middle;

    .input-group-addon,
    .input-group-btn,
    .form-control {
        width: auto !important;
    }
}
like image 140
Jeewes Avatar answered Oct 11 '22 23:10

Jeewes


i've made it work like this:

<form class="form-inline" role="form">
<div class="row">
    <div class="form-group col-sm-3">
        <div class="input-group"> <span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>

            <input type="email" class="form-control" placeholder="Enter email" />
        </div>
    </div>
    <div class="form-group col-sm-3">
        <div class="input-group"> <span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>

            <input type="password" class="form-control" placeholder="Choose password" />
        </div>
    </div>
    <button type="submit" class="btn btn-default">Create account</button>
</div>

http://jsfiddle.net/n5qmc/

like image 28
Damian Trzepała Avatar answered Oct 12 '22 00:10

Damian Trzepała