I've been looking for this throughout the web and can't even find anyone else even asking this, let alone a solution...
Is there a way to change the color of the highlight area within a text input when text is selected? Not the highlight border or the background, but the portion that appears around the text when you have the text actually selected.
I realise this is an old question but for anyone who does come across it this can be done using
contenteditable
as shown in this JSFiddle.Kudos to Alex who mentioned this in the comments (I didn't see that until now!)
@ Mike Eng,
On selecting the text background color, text color can be changed with the help of ::selection, note that ::selection works in in chrome, to make that work in firefox based browsers try this one ::-moz-selection
Try the following snippet of code in reset.css or the css page where exactly you want to apply the effect.
The above code will work even in the input boxes too.
Here is the rub:
Within the selection selector, color and background are the only properties that work. What you can do for some extra flair, is change the selection color for different paragraphs or different sections of the page.All I did was use different selection color for paragraphs with different classes:
Note how the selectors are not combined, even though >the style block is doing the same thing. It doesn't work if you combine them:That's because browsers ignore the entire selector if there is a part of it they don't understand or is invalid. There is some exceptions to this (IE 7?) but not in relation to these selectors.
DEMO
LINK WHERE INFO IS FROM
All answers here are correct when it comes to the
::selection
pseudo element, and how it works. However, the question does in fact specifically ask how to use it on text inputs.The only way to do that is to apply the rule via a parent of the input (any parent for that matter):