html - 在内联表单中使用输入组

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

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

这似乎是因为 input-group 包装器类将 display 设置为 table 而其他输入工作正常,将它们的 display 设置为 inline-block。当然,不可能给 input-group inline-block 显示,因为它的子 add-on span,有 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>

最佳答案

这确实是一个错误并已解决(查看 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>

关于html - 在内联表单中使用输入组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18189398/

相关文章:

javascript - HTML 链接到 anchor 而不更改 url

html - 为什么顶部切片和中间切片有间隙

html - 使用 CSS 延长按钮的长度

html - Bootstrap 列重新排序和 2 列跨越。我的布局可能吗?

javascript - Bootstrap Carousel 自动启动暂停

javascript - <td> focusin 事件.addclass

html - 如何在另一个 div 中右对齐包含表单的 div?

html - 使用 Bootstrap 4 在移动设备上内嵌导航栏图标?

javascript - Bootstrap 3 悬停时折叠

css - PhantomJS:在呈现的 pdf 中忽略外部 CSS