Typeahead.js会干扰Bootstrap输入组

cai*_*lin 25 html javascript css twitter-bootstrap typeahead.js

如何防止Typeahead.js拆分我的Twitter Bootstrap 3输入组?每当我将Typeahead javascript指向属于输入组的文本区域时,连接的文本区域和提交按钮就会停止连接.这是Typeahead中的一个错误,还是有解决方法?

无需加载Typeahead.JS:

在此输入图像描述

使用Typeahead.JS:

在此输入图像描述

我原来的HTML:

    <div class="col-sm-4 hidden-xs">
    <form class="navbar-form" role="search">
        <div class="input-group">
        <input type="text" id="tags" class="form-control" name="q">
            <div class="input-group-btn">
                <button class="btn btn-default" type="submit">Search</button>
            </div>
        </div>
    </form> 
    </div>
Run Code Online (Sandbox Code Playgroud)

这是Typeahead对此HTML的作用:

<div class="col-sm-4 hidden-xs">
        <form class="navbar-form" role="search">
            <div class="input-group">
            <span class="twitter-typeahead" style="position: relative; display: inline-block;">
            <input type="text" class="form-control tt-hint" disabled="" autocomplete="off" spellcheck="false" style="position: absolute; top: 0px; left: 0px; border-color: transparent; box-shadow: none; background-attachment: scroll; background-clip: border-box; background-color: rgb(255, 255, 255); background-image: none; background-origin: padding-box; background-size: auto; background-position: 0% 0%; background-repeat: repeat repeat;">
            <input type="text" id="tags" class="form-control tt-input" name="q" autocomplete="off" spellcheck="false" dir="auto" style="position: relative; vertical-align: top; background-color: transparent;">
            <pre aria-hidden="true" style="position: absolute; visibility: hidden; white-space: nowrap; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; word-spacing: 0px; letter-spacing: 0px; text-indent: 0px; text-rendering: auto; text-transform: none;">
            </pre>
            <span class="tt-dropdown-menu" style="position: absolute; top: 100%; left: 0px; z-index: 100; display: none;"><div class="tt-dataset-0"></div>
            </span>
            </span>
                <div class="input-group-btn">
                    <button class="btn btn-default" type="submit">Search</button>
                </div>
            </div>
        </form> 
        </div>
Run Code Online (Sandbox Code Playgroud)

小智 29

.twitter-typeahead{ float:left; width:100%}

  • 这个答案是不正确的,不应该被投赞成票.这使他们更加接近,但它并没有加入它们,它没有做任何关于文本框的左侧是正方形. (2认同)

dan*_*cek 14

这个项目部分解决了我的问题:https://github.com/hyspace/typeahead.js-bootstrap3.less

唯一突出的问题是当我对.btn和.form-control应用阴影效果时,阴影也会在输入字段和按钮之间绘制.

在此输入图像描述

  • @schnauss我也不是,解决方案不依赖于更少. (2认同)

Max*_*oro 7

Bootstrap v4 解决方案:

.input-group > .twitter-typeahead {
   flex: 1 1 auto;
   width: auto;
}
Run Code Online (Sandbox Code Playgroud)