Nick Kahn
Nick Kahn

Reputation: 20078

How to have side by side form fields in boostrap

enter image description here

I'm trying to put together side by side label/input fields but I'm unable to achieve and here is my HTML code:

<div class="col-sm-12 col-md-12">
        <div class="block-flat">
          <div class="header">                          
            <h3>Horizontal Form</h3>
          </div>
          <div class="content">
            <form class="form-horizontal data-parsley-validate" role="form">
              <div class="form-group">
              <label for="inputEmail3" class="col-sm-2 control-label">Name</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="Name" placeholder="Name">
              </div>
              </div>
              <div class="form-group">
              <label for="inputPassword3" class="col-sm-2 control-label">Address</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="Address" placeholder="Address">
              </div>
              </div>
              <div class="form-group">
              <label for="inputEmail3" class="col-sm-2 control-label">City</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="City" placeholder="City">
              </div>
              </div>
              <div class="form-group">
              <label for="inputPassword3" class="col-sm-2 control-label">Country</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="Country" placeholder="Country">
              </div>
              </div>
              <div class="form-group">
              <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
              <div class="col-sm-10">
                <input type="email" class="form-control" id="Email2" placeholder="Email">
              </div>
              </div>
              <div class="form-group">
              <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
              <div class="col-sm-10">
                <input type="password" class="form-control" id="Password2" placeholder="Password">
              </div>
              </div>
              <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <div class="checkbox" >
                <label>
                  <input type="checkbox" class="icheck"> Remember me
                </label>
                </div>
              </div>
              </div>
              <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">Registrer</button>
                <button class="btn btn-default">Cancel</button>
              </div>
              </div>
            </form>
          </div>
        </div>              
      </div>

Here is what it looks when I run the page:

enter image description here

Here is what I'm looking to achieve:

enter image description here

Upvotes: 0

Views: 3755

Answers (3)

Abrar Mahi
Abrar Mahi

Reputation: 145

Should look something like this

<form class="form-horizontal" method="POST">
      <div class="form-row">
        <div class="col">
            ...
        </div>
        
      <div class="col">
          ...
        </div>
      </div>
</form>

make sure to add a new <form class = "form-row"> for new rows of fields

Upvotes: 0

onedevteam.com
onedevteam.com

Reputation: 4178

Surround elements you want in a separate divs

<div class="col-md-6">
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">Name</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="Name" placeholder="Name">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">Address</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="Address" placeholder="Address">
        </div>
    </div>
</div>
<div class="col-md-6">
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">City</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="City" placeholder="City">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">Country</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="Country" placeholder="Country">
        </div>
    </div>
</div>

Upvotes: 6

Matt Waldron
Matt Waldron

Reputation: 314

You need to define a width on the form-group elements.

If you change the <div class="form-group"> to <div class="col-md-4 form-group">. You will define a 3 column layout with each column containing a form grouping.

Upvotes: 0

Related Questions