Search code examples
twitter-bootstrap-3bootstrap-typeaheadbootstrap-tags-input

StyleSheet is missing in Bootstrap3 TagsInput


I tangled this bug for a long period of time. The StyleSheet is missing in Bootstrap3 TagsInput (on my website)

  • This is My website:

enter image description here

and my code is:

$('#TagForm').tagsinput('input').typeahead({ prefetch: '/api/tag/list' }).bind('typeahead:selected', $.proxy(function (obj, datum) { this.tagsinput('add', datum.value); this.tagsinput('input').typeahead('setQuery', ''); }, $('#TagForm')));

  • This is official website:

enter image description here

and the official website's code is:

$('input').tagsinput();

// Adding custom typeahead support using http://twitter.github.io/typeahead.js
$('input').tagsinput('input').typeahead({
   prefetch: 'citynames.json'
}).bind('typeahead:selected', $.proxy(function (obj, datum) {  
  this.tagsinput('add', datum.value);
  this.tagsinput('input').typeahead('setQuery', '');
}, $('input')));

I have compared my code with the code in Official Website, and can't find the problem.


Solution

  • It looks like there are some custom styles applied to the tags-input documentation where you've taken that screenshot. If you want to match it exactly, you should probably copy their app.css file or at least add these styles to your own custom css file:

    .twitter-typeahead .tt-query,
    .twitter-typeahead .tt-hint {
      margin-bottom: 0;
    }
    
    .twitter-typeahead .tt-hint
    {
        display: none;
    }
    
    .twitter-typeahead .hint-small
    {
        height: 30px;
        padding: 5px 10px;
        font-size: 12px;
        border-radius: 3px;
        line-height: 1.5;
    }
    
    .twitter-typeahead .hint-large
    {
        height: 45px;
        padding: 10px 16px;
        font-size: 18px;
        border-radius: 6px;
        line-height: 1.33;
    }
    
    .tt-dropdown-menu {
      min-width: 160px;
      margin-top: 2px;
      padding: 5px 0;
      background-color: #fff;
      border: 1px solid #ccc;
      border: 1px solid rgba(0,0,0,.2);
      *border-right-width: 2px;
      *border-bottom-width: 2px;
      -webkit-border-radius: 6px;
         -moz-border-radius: 6px;
              border-radius: 6px;
      -webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
         -moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
              box-shadow: 0 5px 10px rgba(0,0,0,.2);
      -webkit-background-clip: padding-box;
         -moz-background-clip: padding;
              background-clip: padding-box;
    }
    
    .tt-suggestion {
      display: block;
      padding: 3px 20px;
    }
    
    .tt-suggestion.tt-is-under-cursor {
      color: #fff;
      background-color: #0081c2;
      background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
      background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
      background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
      background-image: -o-linear-gradient(top, #0088cc, #0077b3);
      background-image: linear-gradient(to bottom, #0088cc, #0077b3);
      background-repeat: repeat-x;
      filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0)
    }
    
    .tt-suggestion.tt-is-under-cursor a {
      color: #fff;
    }
    
    .tt-suggestion p {
      margin: 0;
    }
    

    As far as I can tell, these are the relevant ones, but you can always copy over the whole file and eliminate the ones that don't apply.