如何将自举形式的输入与input-group-addons对齐? [英] How to align inputs in bootstrap form with input-group-addons?

查看:247
本文介绍了如何将自举形式的输入与input-group-addons对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Bootstrap 3表单,当我不使用 input-group-addon s时,我可以轻松(自动)对齐。

I have a very simple form with Bootstrap 3 which I can easily (automatically) align when I don't use input-group-addons.

在我的表单中使用它们之后,它是不可能对齐的(因为添加了插件,插入的行更宽)

After I use them in my form it is impossible to align it (the line with addons is wider because of added 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/

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

推荐答案

输入组的Bootstrap文档说:

Bootstrap documentation for input groups says :


不要将输入组与其他组件混合。(请参阅: http://getbootstrap.com/components/#input-groups

不要混合表单组或网格列直接与输入组相关的类。

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-你必须创建2个div类,第一个使用col-sm-4,另一个使用input-group

So you can't mix "col-sm-4" with "input-group" in the same class. You have to create 2 div class, the first with "col-sm-4" and the other with "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

这篇关于如何将自举形式的输入与input-group-addons对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆