需要正确对齐Bootstrap表单

时间:2015-04-24 05:38:34

标签: html css twitter-bootstrap

我有一个像这样的Bootstrap表单:

enter image description here

===================================================================
col label     col form field ======================================
===================================================================
col label     col form field     | col label     col form field ===
col label     col form field     | col label     col form field ===
===================================================================

2列表单布局工作正常,而在一列中,我无法对齐标签和表单字段,类似于2列表单布局。这是 demo

HTML:

<div>
    <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 col-md-push-2">
        <div class="form-group">
            <label class="col-xs-12 col-sm-6 col-md-2 col-lg-2 control-label text-right col-sm-pull-2">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-8 col-lg-8">
                <input type="text" class="form-control" />
            </div>
        </div>
    </div>
    <div class="clear12"></div>
    <!-- first col -->
    <div class="col-lg-6 col-md-6 col-sm-10 col-xs-10 marginauto">
        <div class="clear"></div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <select class="form-control">
                    <option value="1" selected>1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <input type="text" class="form-control" />
            </div>
        </div>
    </div>
    <!-- / first col -->
    <!-- second col -->
    <div class="col-lg-6 col-md-6 col-sm-10 col-xs-10 marginauto">
        <div class="hidden_767"></div>
        <div class="form-group">
            <label for="dateFrom" class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <div class="input-group">
                    <input type="text" class="date-picker form-control" />
                    <div class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> 
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="searchCategory" class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <select class="form-control">
                    <option value="1" selected>1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
            </div>
        </div>
    </div>
    <!-- / second col -->
</div>

3 个答案:

答案 0 :(得分:3)

你应该使用水平形式来达到预期的效果。请在下面找到小提琴的链接

小提琴: https://jsfiddle.net/nileshmahaja/4cbzY/617/

<强> HTML

<div class="form-horizontal">

  <div class="form-group">
    <div class="col-md-3 col-sm-3">
      <label class="control-label">Label</label>
    </div>
    <div class="col-md-9 col-sm-9">
      <input type="text" class="form-control">
    </div>
  </div>

  <div class="form-group">
    <div class="col-md-3 col-sm-3">
      <label class="control-label">Label</label>
    </div>
    <div class="col-md-3 col-sm-3">
      <input type="text" class="form-control">
    </div>
    <div class="col-md-3 col-sm-3">
      <label class="control-label">Label</label>
    </div>
    <div class="col-md-3 col-sm-3">
      <input type="text" class="form-control">
    </div>
  </div>

  <div class="form-group">
    <div class="col-md-3 col-sm-3">
      <label class="control-label">Label</label>
    </div>
    <div class="col-md-3 col-sm-3">
      <input type="text" class="form-control">
    </div>
    <div class="col-md-3 col-sm-3">
      <label class="control-label">Label</label>
    </div>
    <div class="col-md-3 col-sm-3">
      <input type="text" class="form-control">
    </div>
  </div>

    <!-- / second col -->
</div>

答案 1 :(得分:0)

没关系......

$route['Parivar/admin'] = 'the controller where you want to go';

<强> DEMO

答案 2 :(得分:0)

我认为你需要这样

<div>
    <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 col-md-push-2">
        <div class="form-group">
            <label class="col-xs-12 col-sm-6 col-md-2 col-lg-2 control-label text-right col-sm-pull-2">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-8 col-lg-8">
                <input type="text" class="form-control" />
            </div>
        </div>
    </div>
    <div class="clear12"></div>
    <!-- first col -->
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 marginauto">
        <div class="clear"></div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <select class="form-control">
                    <option value="1" selected>1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <input type="text" class="form-control" />
            </div>
        </div>
    </div>
    <!-- / first col -->
    <!-- second col -->
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 marginauto">
        <div class="hidden_767"></div>
        <div class="form-group">
            <label for="dateFrom" class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <div class="input-group">
                    <input type="text" class="date-picker form-control" />
                    <div class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> 
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="searchCategory" class="col-xs-12 col-sm-6 col-md-5 col-lg-5 control-label text-right">Label</label>
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
                <select class="form-control">
                    <option value="1" selected>1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
            </div>
        </div>
    </div>
    <!-- / second col -->
</div>