Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create bootstrap form having horizontal and vertical form field

Is there anyway I can create a form using bootstrap which can have fields aligned in same line as well as horizontal fields?

enter image description here

Something like this?

in this the cvv MM and YY are in the same line..How can i make it possible using bootstrap form?

<form role="form">
            <div class="form-group">
                 <label for="exampleInputEmail1">Email address</label><input type="email" class="form-control" id="exampleInputEmail1" />
                </div>
<div class="form-group">
                 <label for="exampleInputEmail1">CVV</label><input type="email" class="form-control" id="cvv" />
                </div>
            <div class="form-group">
                 <label for="exampleInputPassword1">Password</label><input type="password" class="form-control" id="exampleInputPassword1" />
                </div>

            <button type="submit" class="btn btn-default">Submit</button>
        </form>
    </div>

I want the cvv to be aligned with the first form field

like image 415
user3150930 Avatar asked Jan 01 '14 09:01

user3150930


People also ask

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.

How do I split a two column form in Bootstrap?

You can add columns and rows by adding <div class="row"> and <div class="col"> to your form. In the example above, the email and password fields are separated into two columns within a row. This is why they are displayed side by side on a webpage.


1 Answers

Wrap your input fields in a div and assign a col-sm-x class to it e.g:

<div class="form-group">
    <label class="col-sm-3 control-label" for="cardNumber">Card # (required)</label>
    <div class="col-sm-5">
        <input type="text" class="form-control" id="cardNumber" size="12" autocomplete='off'>
    </div>
</div>

Also add a col-sm-x to your labels

For columns:

<div class="form-group">
    <label class="col-sm-3 control-label">Expiry date(MM/YYYY) (required)</label>
    <div class="col-sm-2">
        <input type="text" class="form-control" placeholder="MM" size="2" autocomplete='off'>
    </div>
    <div class="col-sm-2">
        <input type="text" class="form-control" placeholder="YYYY" size="4" autocomplete='off'>
    </div>
</div>

Finally, class of form should be form-horizontal Play with the col width as you like

like image 53
Emmanuel John Avatar answered Nov 15 '22 08:11

Emmanuel John