【问题标题】:Using input-group inside an inline form在内联表单中使用输入组
【发布时间】:2013-08-13 21:45:38
【问题描述】:

input-group 附加到form-inline 时,input-group 将出现在表单下方的“新行”上,而不是与其他控件内联。

这似乎是因为input-group 包装类将display 设置为table,而其他工作正常的输入将display 设置为inline-block。当然,不可能给input-group提供inline-block显示,因为它的子add-on跨度有display: table-cell,需要父的属性才能正确对齐。

所以我的问题是:是否可以在内联表单中使用input-group仅使用 Bootstrap 类?如果没有,最好的解决方法是允许使用自定义类

这是一个demo 说明我的观点。代码如下:

<form action="" class="form-inline">
    <input type="text" class="form-control" placeholder="Works with" style="width: 100px;"/>
    <input type="text" class="form-control" placeholder="Text Inputs" style="width: 120px;"/>

    <div class="checkbox">
        <label>
            <input type="checkbox" /> and Checkboxes
        </label>
    </div>
    <select class="form-control" style="width: 150px;">
        <option>and Selects</option>
    </select>

    <button type="submit" class="btn btn-default">and Buttons</button>
    <div class="input-group" style="width: 220px;">
        <span class="input-group-addon">BUT</span>
        <input type="text" class="form-control" placeholder="not with input-groups" />
    </div>
</form>

【问题讨论】:

  • 这是一个错误,也许你可以在 input-group 类中使用 pull-right
  • 是的,这可能是一个错误。无论我的情况如何,使用pull-right 都不是一个好的解决方案:输入之间的垂直间距丢失,并且如果有两个输入组,它们将被错误地显示。恕我直言,最好使用带有自定义类的功能解决方案,而不是使用内置类的错误破解。

标签: html css twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

这确实是一个错误并已解决(查看issue on github 了解更多信息)。

从现在开始,BootStrap 中的内联表单需要使用.form-group 包装子表单控件。

所以我的代码会变成:

<form action="" class="form-inline">
    <div class="form-group">
        <input type="text" class="form-control" placeholder="Works with" style="width: 100px;"/>
    </div>

    ...
    <div class="form-group">
        <div class="input-group" style="width: 220px;">
            <span class="input-group-addon">BUT</span>
            <input type="text" class="form-control" placeholder="not with input-groups" />
        </div>
    </div>
</form>

【讨论】:

  • 我在 3.0.3 上,但我仍然有这个问题。在表单控件创建新行之后添加输入组插件
  • @Marc :我在 3.0.3 上,做你想做的事“form.form-inline { display: inline; } form.form-inline .form-group .input-组输入 + .input-group-addon { 宽度:初始;}"。不知道是不是所有浏览器都兼容。
  • @Marc : 我忘了说输入需要一个宽度或最大宽度。
  • +1 我希望这在文档中更明显!
  • @edsioufi 使用 Bootstrap 3.2.0 回答的工作示例:jsfiddle
【解决方案2】:

我认为您可能需要将表单分成几列以获得所需的内联布局。 Bootstrap 站点here 上有一个示例(我想到了您所追求的)。

试试看

<div class="col-lg-1"></div>

围绕你的控件看看我的意思。您当然需要在 12 列中工作,因此需要相应地进行调整。

【讨论】:

  • 我们可以使用列来对齐任何表单控件(不管有问题的input-group)。尽管如此,BootStrap 仍然提供了form-inline 类(如果鼓励使用列,这将是不必要的)。这个demo 让我觉得内联表单存在的原因是从响应式设计的角度来看,使用列并不能产生好的结果。我仍然更喜欢自定义类而不是柱状设计(或者甚至改用horizontal-forms)。
猜你喜欢
  • 2014-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多