如何在boostrap中并排表单字段

时间:2015-11-03 14:38:52

标签: html css twitter-bootstrap twitter-bootstrap-3

enter image description here

我试图将标签/输入字段放在一起,但我无法实现,这是我的HTML代码:

<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>

这是我运行页面时的样子:

enter image description here

以下是我希望实现的目标:

enter image description here

2 个答案:

答案 0 :(得分:5)

您想要在单独的div中的环绕元素

<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>

答案 1 :(得分:0)

您需要在表单组元素上定义宽度。

如果您将<div class="form-group">更改为<div class="col-md-4 form-group">。您将定义一个3列布局,每列包含一个表单分组。