Search code examples
javascripttwitter-bootstraptypeahead.jstwitter-typeahead

Styling the typeahead.js list (the bootstrap way)


I'm trying to create an autocomplete text field using typeahead.js. The examples here show suggestion lists that are nicely formatted. However, when I use the same code, I only get a bland list of suggestions like so:

Please see this jsFiddle for the code.

I'm using Bootstrap with it. What do I have to do to get a list that is formatted the Bootstrap way?


Solution

  • It looks like the default output has no styling at all and the .tt class has to be used to style the list. I got the following code by inspecting the element I wanted, tweak to suit your needs.

    .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 {
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
    }
    
    .tt-hint {
        color: #999
    }
    
    .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-cursor {
        color: #fff;
        background-color: #0097cf;
    
    }
    
    .tt-suggestion p {
        margin: 0;
    }