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
or 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 sideba开发者_如何学运维r 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?
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.
In my recall, the foreground and background colors are read from system colors and cannot be controlled by CSS.
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.
精彩评论