2

我正在尝试在引导程序中创建表单水平表单,但是当我尝试在控制字段上添加 input-append 时,该字段会向右移动。我无法找到它发生的确切原因......或者我做错了什么。我正在尝试使用密码输入字段添加一个简单的 PWD...

<form class="bs-docs-example form-horizontal">
            <div class="control-group">
              <label class="control-label" for="inputEmail">Email</label>
              <div class="controls">
                <input type="text" id="inputEmail" placeholder="Email">
              </div>
            </div>
            <div class="control-group">
              <label class="control-label" for="inputPassword">Password</label>
              <div class="controls input-append">
                <input type="password" id="inputPassword" placeholder="Password">
                    <span class="add-on">PWD</span>
              </div>
            </div>
            <div class="control-group">
              <div class="controls">
                <label class="checkbox">
                  <input type="checkbox"> Remember me
                </label>
                <button type="submit" class="btn">Sign in</button>
              </div>
            </div>
          </form>

这是一个 jsfiddle .. http://jsfiddle.net/zEUH4/

谢谢。

4

3 回答 3

4

正确的结构是:

<div class="control-group">
  <label class="control-label" for="inputPassword">Password</label>
  <div class="controls">
    <div class="input-append">
      <input type="password" id="inputPassword" placeholder="Password">
      <span class="add-on">PWD</span>
    </div>
  </div>
</div>
于 2013-07-16T11:38:29.750 回答
3

如果您采用 input-append 类并将其移动到应该解决您的问题的控制组 div 上。

http://jsfiddle.net/zEUH4/1/

<div class="control-group input-append">
  <label class="control-label" for="inputPassword">Password</label>
  <div class="controls">
    <input type="password" id="inputPassword" placeholder="Password">
    <span class="add-on">PWD</span>
  </div>
</div>
于 2013-02-08T12:09:37.890 回答
2

该类.input-append添加display: inline-block;<div>. 将.controlsa 添加margin: 180px<div>通常距左边缘 180px 的位置,但现在距<label>.

这 2 个类不打算用于 1 个元素。

<form class="bs-docs-example form-horizontal">
    <div class="control-group">
        <label class="control-label" for="inputEmail">Email</label>
        <div class="controls">
            <input type="text" id="inputEmail" placeholder="Email">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputPassword">Password</label>
        <div class="controls">
            <div class="input-append">
                <input type="password" id="inputPassword" placeholder="Password">
                <span class="add-on">PWD</span>
            </div>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <label class="checkbox"><input type="checkbox">Remember me</label>
            <button type="submit" class="btn">Sign in</button>
        </div>
    </div>
</form>

看小提琴

或者,您将 设置<div>display: block

<div class="control-group">
    <label class="control-label" for="inputPassword">Password</label>
    <div class="controls input-append" style="display: block">
        <input type="password" id="inputPassword" placeholder="Password">
        <span class="add-on">PWD</span>
    </div>
</div>
于 2013-02-08T12:20:26.740 回答