Facebook Search

Example HTML

                                
<div class="input-wrapper">
    <label for="autocomplete-1"><span class="sr-only">Example search</span></label>
    <input type="text" id="autocomplete-1" placeholder="Search Google"/>
    <button class="btn-search"><span class="icon-search"></span></button>
</div>
                                
                            

Example CSS

                                
.facebook {
    background: linear-gradient(to top, #4D6BA1, #3B5998);
    font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;
}
.facebook .demo-title {
    color: #fff;
}
.facebook .input-wrapper {
    position: relative;
    max-width: 600px;
    margin: 0 auto;
    clear: both;
}
.facebook .btn-search {
    position: absolute;
    content: '';
    background: #f6f7f8;
    color: #535C68;
    border: 1px solid #355089;
    border-left: 0;
    border-radius: 0 4px 4px 0;
    cursor: default;
    display: block;
    height: 26px;
    width: 50px;
    line-height: 1;
    right: 0;
    text-align: center;
    top: 0;
    z-index: 1;
}
.facebook label {
    position: absolute;
    right: 100%;
}
.facebook label .icon-db {
    color: #fff;
    display: block;
    border-radius: 4px;
    overflow: hidden;
    height: 26px;
    width: 27px;
    margin-right: 5px;
    border: 1px solid #355089;
    text-align: center;
}
.facebook label .icon-db:before {
    font-size: 26px;
}
.facebook input {
    width: 100%;
    border: 1px solid #355089;
    border-radius: 4px;
    height: 26px;
    padding-left: 5px;
    font-size: .875em;
}
.facebook input:focus ~ .btn-search {
    background-color: #5890ff;
    color: #fff;
}
.facebook .autocomplete-suggestions {
    background-color: #fff;
    border-radius: 4px;
    border: 1px solid #ccc;
    box-shadow: 0 4px 6px 2px rgba(0, 0, 0, 0.1);
    font-size: .875em;
    margin-left: 1px;
    clear: both;
}
.facebook .autocomplete-suggestion {
    position: relative;
    cursor: pointer;
}
.facebook .autocomplete-selected {
    background-color: #EBEEF4;
}
.facebook .autocomplete-suggestions strong {
    font-weight: 700;
}
.facebook .suggestion-img {
    float: left;
    height: 40px;
    line-height: 40px;
    margin: 4px 8px 0 6px;
    overflow: hidden;
    text-align: center;
    vertical-align: middle;
    width: 40px;
}
.facebook .suggestion-img img {
    max-width: 100%;
    max-height: 40px;
    display: block;
}
.facebook .suggestion-wrapper {
    display: block;
    height: 48px;
    overflow: hidden;
    position: relative;
    text-overflow: ellipsis;
    vertical-align: middle;
    line-height: 16px;
    padding: 7px 0;
}
.facebook .suggestion-value {
    display: block;
    line-height: normal;
    font-weight: 700;
}
.facebook .sub-text {
    color: #999;
    font-size: 11px;
    font-weight: normal;
}
                                
                            

Example JavaScript

                                
var element = document.getElementById('autocomplete-1');

var options = {
    serviceUrl: '/scripts/suggestions-fb.json',
    minChars: 1,
    autoSelectFirst: true,
    appendTo: element.parentNode,
    formatResult: function (suggestion) {
        return "<span class='suggestion-img'><img src='" + suggestion.data.img + "'/>" +
            "</span><span class='suggestion-wrapper'><span class='suggestion-value'>" + suggestion.value + "</span>" +
            "<span class='sub-text'>" + suggestion.data.location + "</span>" +
            "<span class='sub-text'>" + suggestion.data.likes + "</span></span>";
    }
};

var instance = new autocomplete(element, options);
                                
                            

Google Search

Example HTML

                                
<div class="input-wrapper">
    <label for="autocomplete-2"><span class="sr-only">Example search</span></label>
    <input type="text" id="autocomplete-2" placeholder="Search Google"/>
    <button class="btn-search"><span class="icon-search"></span></button>
</div>
                                
                            

Example CSS

                                
.google {
    background-color: #F1F1F1;
    font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;
}
.google .demo-title {
    color: #000;
    margin-bottom: 1em;
}
.google .demo-title img {
    max-width: 269px;
}
.google .input-wrapper {
    position: relative;
    max-width: 600px;
    margin: 0 auto;
    clear: both;
}
.google .input-wrapper:before {
    position: absolute;
    right: 65px;
    top: 3px;
    content: '';
    width: 17px;
    height: 23px;
    background: url("data:image/gif;base64,R0lGODlhHAAmAKIHAKqqqsvLy0hISObm5vf394uLiwAAAP///yH5BAEAAAcALAAAAAAcACYAAAO9eLpMIMYIQJi9DcYtKv6KtnHgB4yoAZSXKAyDy1rjoAzjzOQLrx8+4OanCAZnxiExGSEKmz3lj2lwUq3SZ3WZPbKuXGgxu9t4tLYDTkpIRQILF0x2G4lWipM7gj/oJQUkcXsCDCIFATULBCIcZ2tvB3QLDxETFnR/BgU/gRt9jX0gnpYMkJZpFzEoqQqJKAIBaQOVKHAXr3t7txgBjboSvB8EpLoFZywOAo3LFE5lYs/QW9LT1TRk1V7S2xYJADs=") no-repeat center center;
    background-size: 14px 19px;
    opacity: .6;
}
.google .input-wrapper:hover:before {
    opacity: 1;
}
.google label {
    position: absolute;
    right: 100%;
}
.google label .icon-db {
    color: red;
    display: block;
    border-radius: 4px;
    overflow: hidden;
    height: 26px;
    width: 27px;
    margin-right: 5px;
    border: 1px solid red;
    text-align: center;
}
.google label .icon-db:before {
    font-size: 26px;
}
.google input {
    width: 100%;
    border: 1px solid #A0A0A0;
    height: 30px;
    padding-left: 5px;
    font-size: .875em;
    border-radius: 0 4px 4px 0;
}
.google input:focus {
    border-color: #4d90fe;
}
.google input:focus ~ .btn-search {
    background-color: #5890ff;
    color: #fff;
}
.google .btn-search {
    position: absolute;
    content: '';
    background: linear-gradient(#4d90fe, #4787ed);
    color: #fff;
    border: 1px solid #4d90fe;
    border-left: 0;
    cursor: default;
    display: block;
    height: 30px;
    width: 60px;
    line-height: 1;
    right: 0;
    text-align: center;
    top: 0;
    z-index: 1;
    border-radius: 0 4px 4px 0;
}
.google .btn-search .icon-search {
    font-size: 14px;
}
.google .autocomplete-suggestions {
    background-color: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 4px 6px 2px rgba(0, 0, 0, 0.1);
    font-size: .875em;
    margin-top: -1px;
    overflow: hidden;
}
.google .autocomplete-suggestion {
    position: relative;
    cursor: pointer;
    font-weight: 700;
    line-height: 22px;
    padding: 0 5px;
}
.google .autocomplete-selected {
    background-color: #EBEEF4;
}
.google .autocomplete-suggestions strong {
    font-weight: 100;
}

                                
                            

Example JavaScript

                                    
var element = document.getElementById('autocomplete-2');

var options = {
    serviceUrl: '/scripts/suggestions-fb.json',
    minChars: 1,
    autoSelectFirst: true,
    appendTo: element.parentNode,
    formatResult: function (suggestion) {
    return "<span class='suggestion-img'><img src='" + suggestion.data.img + "'/>" +
    "</span><span class='suggestion-wrapper'><span class='suggestion-value'>" + suggestion.value + "</span>" +
    "<span class='sub-text'>" + suggestion.data.location + "</span>" +
    "<span class='sub-text'>" + suggestion.data.likes + "</span></span>";
    }
};

var instance = new autocomplete(element, options);