html – 如何将引导形式的输入与input-group-addons对齐?

我有一个非常简单的形式与Bootstrap 3,我可以很容易地(自动)对齐,当我不使用input-group-addons。

在我以我的形式使用它们之后,它是不可能对齐的(由于添加了插件,与插件的线更宽)

<form class="form-horizontal" role="form">

    <div class="form-group">
      <label for="product_name" class="col-sm-2 control-label">Product name</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="product_name" placeholder="Product name">
      </div>
    </div>

    <div class="form-group">
      <label for="product_price" class="col-sm-2 control-label">Price</label>
      <div class="col-sm-4 input-group">
        <span class="input-group-addon">$</span>
        <input type="text" class="form-control bfh-number" id="product_price" placeholder="Price" data-min="0" data-max="9999999">
        <span class="input-group-addon">.00</span>
      </div>
    </div>

    <div class="form-group">
      <label for="product_description" class="col-sm-2 control-label">Description</label>
      <div class="col-sm-6">
        <textarea class="form-control" id="product_description" placeholder="Description" rows="5"></textarea>
      </div>
    </div>

    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-default">Submit</button>
      </div>
    </div>
</form>

JsFiddle:http://jsfiddle.net/Yzxy3/

输入组的Bootstrap文档说:

Don’t mix input-group with other components. (see:07000)

Do not mix form groups or grid column classes directly with input groups. Instead, nest the input group inside of the form group or grid-related element.”

所以你不能将“col-sm-4”和“input-group”混合在同一个类中。你必须创建2个div类,第一个用“col-sm-4”,另一个用“input-group”

<div class="col-sm-4">
  <div class="input-group">
    <span class="input-group-addon">$</span>
    <input type="text" class="form-control bfh-number" id="product_price" placeholder="Price" data-min="0" data-max="9999999">
    <span class="input-group-addon">.00</span>
  </div>
</div>

Updated Fiddle

http://stackoverflow.com/questions/21340126/how-to-align-inputs-in-bootstrap-form-with-input-group-addons

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:html – 如何将引导形式的输入与input-group-addons对齐?