Bootstrap“形式水平”和标签

时间:2014-11-17 10:12:26

标签: css twitter-bootstrap

我在创建一个" form-horizo​​ntal"用bootstrap。

http://jsfiddle.net/frauger/jo0b6yod/

正如你在jsfiddle中看到的标签"出生日期"未在出生日期之前正确对齐"出生日期选择"

<form class="form-horizontal">
<div class="form-group">
    <label for="name" class="col-xs-2 control-label">Name</label>
    <div class="col-xs-10">
        <input type="text" class="form-control col-sm-10" name="name" placeholder="name"/>
    </div>
</div>

<div class="form-group">
    <label for="birthday" class="col-xs-3 col-sm-2 control-label">Birthday</label>
    <div class="col-xs-3">
        <input type="text" class="form-control" placeholder="year"/>
    </div>
    <div class="col-xs-3">
        <input type="text" class="form-control" placeholder="month"/>
    </div>
    <div class="col-xs-3">
        <input type="text" class="form-control" placeholder="day"/>
    </div>    
</div>

由于

2 个答案:

答案 0 :(得分:2)

将所有现有select divs包装在具有div类的新容器form-group中。

<div class="form-group">
    <div class="col-xs-4">
         <select type="text" class="form-control" id="field-day" required>
             <option>DD</option>
         </select>
    </div>
    <div class="col-xs-4">
         <select type="text" class="form-control" id="field-month" required>
             <option>MM</option>
         </select>
    </div>
    <div class="col-xs-4">
         <select type="text" class="form-control" id="field-year" required>
             <option>YYY</option>
         </select>
    </div>
</div>

工作小提琴: http://jsfiddle.net/jo0b6yod/2/

答案 1 :(得分:0)

在div标签中包含标签,该标签应使标签处于块级别,并占用其父级的100%。

例如:

<div class="form-group">
    <div><label for="birthday" class="col-xs-3 col-sm-2 control-label">Birthday</label></div>
  <div class="col-xs-3">
    <input type="text" class="form-control" placeholder="year"/>
  </div>
  <div class="col-xs-3">
    <input type="text" class="form-control" placeholder="month"/>
  </div>
  <div class="col-xs-3">
    <input type="text" class="form-control" placeholder="day"/>
  </div>    
</div>