Typeahead.js会干扰Bootstrap输入组

时间:2014-03-08 23:38:41

标签: javascript html css twitter-bootstrap typeahead.js

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

不加载Typeahead.JS:

enter image description here

使用Typeahead.JS:

enter image description here

我原来的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>

这是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>

5 个答案:

答案 0 :(得分:28)

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

答案 1 :(得分:12)

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

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

enter image description here

答案 2 :(得分:2)

这解决了当文本框的左侧是方形(不是圆角)时的问题:

.input-group .twitter-typeahead .form-control:not(:first-child):not(:last-child) {
  border-radius: 4px 0px 0px 4px;
}

答案 3 :(得分:2)

可能?

.twitter-typeahead > .form-control{
  width: inherit !important;
}

答案 4 :(得分:2)

Bootstrap v4解决方案:

.input-group > .twitter-typeahead {
   flex: 1 1 auto;
   width: auto;
}