Styling autocomplete dropdowns in browsers
Nope. Autocomplete is not a part of any standard, and is not part of the DOM. The only way to style is, as you've suggested yourself, by recreating that functionality using JavaScript.
How to style autocomplete dropdown list
Apparently the autocomplete dropdown box cannot be edited with CSS and is not part of the DOM. I found this information from the following (duplicate) questions.
How to style the browser's autocomplete dropdown box?
Styling autocomplete dropdowns in browsers
Styling suggestions dropdown
No, it is browser's native implementation. the browser doesn't even add or modify any new DOM element therefore you can not style the dropdown list. I am not 100% sure but it looks like the drop down list is on a different layer on top of the display page. You will need to have a your own Javascript implementation of autocomplete.
By the way to disable this browser behavior, add this to the input element:
autocomplete="off"
Note that not all browser support autocomplete attribute
Is there a way to edit the styling of the suggestions given when typing in an input tag?
That is browser specific so no. Instead, you could build a custom system where you save the previously entered values in 'local storage' via javascript and then use an auto-complete library to display the previous entries how you like.
Some example code:
http://jsfiddle.net/R2TGL/
<input type="text" id="savedInput"/>
window.onload = function(){
$('#savedInput').autocomplete({
source:JSON.parse(localStorage.previousInputs)
});
$('#savedInput').change(function(){
if( localStorage.previousInputs == undefined ) {
localStorage.previousInputs = JSON.stringify([]);
}
var prevArray = JSON.parse(localStorage.previousInputs);
prevArray.push($(this).val());
localStorage.previousInputs = JSON.stringify(prevArray);
$('#savedInput').autocomplete({
source:JSON.parse(localStorage.previousInputs)
});
});
}
Related Topics
How to Align Caption Underneath Image
Link External CSS File Only for Specific Div
Align Flex Items with Different Heights in The Same Container
How to Render Svg Elements with Crisp Edges While Still Keeping Anti-Aliasing
Emoji Rendered in Chrome Have Different Widths Than in Other Browsers
Force Ie Contenteditable Element to Create Line Breaks on Enter Key, Without Breaking Undo
Making Part of a Div Transparent
Elements in a Flex Container Are Not Wrapping
Why Is My .Sticky-Top Class Not Working in Bootstrap 4
W3C Markup Validator Ampersand (&) Error
HTML Form File Uploads Doesn't Upload File
Multiple Background Images in One Div
How to Make a Transparent Border Using CSS
Break Long Word in Table Cell with Percentage Widths