7

I've been using the following CSS3 option to change the highlight color of text on a webpage. However, the only element on the webpage is a textarea, and the following CSS doesn't seem to do anything.

::selection { background:#B9B9B9; color:#000000; }

Am I doing it wrong? Is it possible to change the highlight color of a textarea? Or am I just wasting my time?

木川 炎星
  • 3,893
  • 13
  • 42
  • 51
  • Is that the exact CSS style you are using? As it should be textarea::selection { ... } – Kyle Ross Aug 14 '10 at 03:45
  • 1
    Hmm. I can't get it to work even with the textarea::selection { ... } syntax. I've also tried #editor.::selection { ... } but that also doesn't work. I don't suppose it could be a browser issue? I've tested it in Chrome, Safari, Firefox, and IE8. – 木川 炎星 Aug 14 '10 at 03:54

1 Answers1

8

Try using the vendor extension versions -moz-selection and -webkit-selection:

::selection { background:#B9B9B9; color:#000000; }
::-moz-selection { background:#B9B9B9; color:#000000; }
::-webkit-selection { background:#B9B9B9; color:#000000; }

Note that the selection pseudo has been removed from the current draft.

robertc
  • 74,533
  • 18
  • 193
  • 177