【问题标题】:Boostrap 3 input with addon and help block带有插件和帮助块的 Bootstrap 3 输入
【发布时间】:2016-06-06 15:49:17
【问题描述】:

使用 Bootstrap CSS 3.3.1,我在使用插件和帮助块的输入时遇到了一点问题。

看看小提琴:https://jsfiddle.net/L8cyqoL1/1/

在 Firefox / Chrome 上测试。标记错了吗?我尝试了“input-group”...作为类但没有成功

这是标记:

<div class="form-group">
    <label for="title" class="control-label col-md-3">Titre de la page</label>
    <div class="col-md-9 input-group">
        <div class="input-group-addon">
            @
        </div>
        <input type="text" value="Value test" class="form-control input-xxlarge" id="title" name="title" size="46" />
            <span class="help-block">Help Lorem Ipsum</span>
    </div>
</div>

【问题讨论】:

  • 只需将help-block 放在input-group 之外,因为它不是其中的一部分。您还应该避免将input-groupcol-* 混合使用

标签: css twitter-bootstrap


【解决方案1】:

试试这样:

<div class="form-horizontal">
    <div class="form-group">
        <label for="title" class="control-label col-sm-3">Titre de la page</label>
        <div class="col-sm-9">
            <div class="input-group">
              <span class="input-group-addon">@</span>
                <input type="text" id="title" name="title"  class="form-control" />
            </div>
            <p class="help-block">Example block-level help text here.</p>
        </div>
    </div>
</div>

this updated fiddle

(拉伸预览窗格以查看列支持)

【讨论】:

  • OK 似乎以这种方式工作,感谢您的提琴。它只需要 DOM 中的新 div 容器 :( .
  • 如果您需要输入范围较窄但提示范围较宽,则此方法不起作用。
【解决方案2】:

可以接受已接受的答案,但如果您仍然需要在 input-group 中使用 help-block(我需要它来支持我的工作 javascript 以显示内联错误),那么有一种解决方法可以解决该问题并具有跨浏览器支持。

.input-group .help-block{
  display: table-row;
}

这里是小提琴:https://jsfiddle.net/L4joxj90/2/ (这只是有一个限制,我们不能使用输入字段左侧的 input-group-addon)

【讨论】:

  • 感谢您提供此答案。在我自己的标记中,help-block 在多个模板中位于 input-group 内,因此更改标记很乏味。你的回答减轻了我的压力。谢谢!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多