tags:

views:

50

answers:

3

Supposing no CSS, javascript or other HTML trickery, how does the browser determine the color of the text and background for selected text?

For example, standard white background (#FFFFFF, or RGB=255,255,255) with black text (#000000 RGB=0,0,0) when selected with invert the colors (i.e. black background, white text.) How are other colors chosen? For example, when writing a question on this site, the right sidebar has an area "How to ask" with background #FFEFC6 and text #AE0000, which when selected become #3399FF and #FFFFFF respectively.

I would like to know how this is determined (is there an algorithm or just defaults) and is this the same across browsers?

+1  A: 

In my recall, the foreground and background colors are read from system colors and cannot be controlled by CSS.

Joshua
+1  A: 

I'd agree with Joshua that the colors come from the system, but I'd disagree about CSS, for example, CSS-Tricks:

::selection { background: #ffcc89; color: #222; }
::-moz-selection { background: #ffcc89; color: #222; }

For more info, see Quirksmode on selection styles.

Skilldrick
Great. Confirmed: I've tinkered with the system settings and, in Windows Vista, "Selected Items" has a background and font setting. Other OS will, of course, differ. Thanks for the CSS tips.
kevininspace
A: 

I believe that each operating/windowing system has its own algorithm. On many, you can select from a few different schemes. It will NOT be the same across all browsers.

For example, in Safari on my Mac, selecting black text on a white background results in a blue rectangle around black text.

Scott Saunders