0

在我的 webapp 项目中,我使用 Bootstrap 作为前端框架。还有一个问题让我感到困惑。HTML 代码如下:

    <form class="form-horizontal" role="form">
    <div class="form-group">
        <label class="control-label col-lg-2" for="candidatecity">Cities</label>
        <div class="col-lg-2">
            <select class="form-control" ng-options="city for city in avaiablecities" ng-model="selectedCity" id="candidatecity" ></select>
        </div>
        <div class="input-group col-lg-2">
            <span class="input-group-addon glyphicon glyphicon-search"></span><input type="text" class="form-control" id="searchcity" placeholder = "Search City">
        </div>

        <label class="control-label col-lg-2" for="period">Time Period</label>
        <div class="col-lg-2">
            <select class="form-control"  ng-options="period for period in avaiableperiod" ng-model="selectedperiod" id="period"></select>
        </div>

        <div class="col-lg-2">
            <button type="submit" class="btn btn-default" ng-click="clickSendRequest()">Get Data</button>
        </div>
    </div>

</form>

但结果如下: 在此处输入图像描述

令人困惑的一点是所有列的宽度加起来只有12,这符合网格系统规则。但是为什么不能将这些组件放在一行中呢?

4

2 回答 2

0

是因为input-group上课。如果删除它,元素将排成一行:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">


<form class="form-horizontal" role="form">
  <div class="form-group">
    <label class="control-label col-lg-2" for="candidatecity">Cities</label>
    <div class="col-lg-2">
      <select class="form-control" ng-options="city for city in avaiablecities" ng-model="selectedCity" id="candidatecity" ></select>
    </div>
    <div class="col-lg-2">
      <span class="input-group-addon glyphicon glyphicon-search"></span><input type="text" class="form-control" id="searchcity" placeholder = "Search City">
    </div>

    <label class="control-label col-lg-2" for="period">Time Period</label>
    <div class="col-lg-2">
      <select class="form-control"  ng-options="period for period in avaiableperiod" ng-model="selectedperiod" id="period"></select>
    </div>

    <div class="col-lg-2">
      <button type="submit" class="btn btn-default" ng-click="clickSendRequest()">Get Data</button>
    </div>
  </div>

</form>

之后,您需要正确设置搜索图标的样式。

于 2016-05-31T20:40:00.060 回答
0

尝试使用

<div class="col-lg-2">
  <div class="input-group">
    ...
  </div>
</div>

代替

<div class="input-group col-lg-2">
  ...
</div>

检查结果:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<form class="form-horizontal" role="form">
  <div class="form-group">
    <label class="control-label col-lg-2" for="candidatecity">Cities</label>
    <div class="col-lg-2">
      <select class="form-control" ng-options="city for city in avaiablecities" ng-model="selectedCity" id="candidatecity" ></select>
    </div>
    <div class="col-lg-2">
      <div class="input-group">
        <span class="input-group-addon glyphicon glyphicon-search"></span><input type="text" class="form-control" id="searchcity" placeholder = "Search City">
      </div>
    </div>

    <label class="control-label col-lg-2" for="period">Time Period</label>
    <div class="col-lg-2">
      <select class="form-control"  ng-options="period for period in avaiableperiod" ng-model="selectedperiod" id="period"></select>
    </div>

    <div class="col-lg-2">
      <button type="submit" class="btn btn-default" ng-click="clickSendRequest()">Get Data</button>
    </div>
  </div>

</form>

于 2016-05-31T21:55:31.943 回答