javascript - Twitter 的 typeahead.js 建议没有样式(没有边框、透明背景等)

标签 javascript css typeahead.js

我正在使用推特的 typeahead.js 0.9.3看来我的建议根本没有风格。

我知道了:

typeahead bug

不是这样的:(取自 examples page)

typehead ideal

JavaScript 启用 typeahead:

$('.search-typeahead').typeahead({
    name: 'videos',
    remote: {
        url: '/api/v1/internal/videos/typeahead?text=%QUERY'
    }
});

HTML 输入元素:

<input type="text" value="" id="search_keywords" class="no-clear search-typeahead"/>

附加说明:

我正在处理的网站有 jQuery 1.10.1,并且不使用 twitter Bootstrap 。有一堆 CSS 不是我写的,因此不熟悉,我担心会干扰,但是插件似乎添加了自己的样式(没有随附的 .css 文件)所以理论上它不应该覆盖东西?我很困惑为什么我的样式有效,但插件添加的样式无效,导致建议具有透明背景、无边框等。

最佳答案

所以查看 docs我现在看到了:

By default, the dropdown menu created by typeahead.js is going to look ugly and you'll want to style it to ensure it fits into the theme of your web page.

因此,我的解决方案是从我希望复制的示例中复制样式:

.tt-query, /* UPDATE: newer versions use tt-input instead of tt-query */
.tt-hint {
    width: 396px;
    height: 30px;
    padding: 8px 12px;
    font-size: 24px;
    line-height: 30px;
    border: 2px solid #ccc;
    border-radius: 8px;
    outline: none;
}

.tt-query { /* UPDATE: newer versions use tt-input instead of tt-query */
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}

.tt-hint {
    color: #999;
}

.tt-menu { /* UPDATE: newer versions use tt-menu instead of tt-dropdown-menu */
    width: 422px;
    margin-top: 12px;
    padding: 8px 0;
    background-color: #fff;
    border: 1px solid #ccc;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    box-shadow: 0 5px 10px rgba(0,0,0,.2);
}

.tt-suggestion {
    padding: 3px 20px;
    font-size: 18px;
    line-height: 24px;
}

.tt-suggestion.tt-is-under-cursor { /* UPDATE: newer versions use .tt-suggestion.tt-cursor */
    color: #fff;
    background-color: #0097cf;

}

.tt-suggestion p {
    margin: 0;
}

关于javascript - Twitter 的 typeahead.js 建议没有样式(没有边框、透明背景等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20198247/

相关文章:

javascript - 如何使用 knockout.js 制作单页应用程序?

css - 网格 CSS 布局。告诉我不使用的原因

android - 雷姆不是雷姆?

基于父类的css动态类

javascript - Bootstrap 中的预输入 :The suggestions keep there when the input doesn't matches

javascript - 数组推送第一次不起作用

c# - 从客户端调用 WCF 服务

javascript - 何时使用 "window.onload"?

html - 悬停时的 css 交换图像无法正常工作 - 悬停图像显示在主图像后面

javascript - 无法读取未定义的属性 'isArray'