tags:

views:

57

answers:

2

Whenever we select some text, the entire text area gets highligted. like this .

but is there any way to do away with this highlighting? I want just the color of the text to change and not the area to be highlighted as it appears in the image? am I clear enough?

A: 

If you're talking about when someone selects the text in the browser (using the mouse or shift-selecting) then this isn't possible.

[UPDATE]

I take it all back - as @Dev F and @nico say, there's a selection CSS3 property. (Of course only some browsers will support this, but...)

middaparka
but i have seen this happen in some sites...
Sachindra
@Sachindra - I suspect that's just coincidence (in that the colour chosen by the browser/OS happened to match the background). In essence, there's no *standard* CSS property that let's you control this.
middaparka
@middaparka: It can actually be done using the `::selection` selector (browser specific).
nico
@nico Updated my answer. You live and learn. :-)
middaparka
+7  A: 

Depends on which browsers you need to support. Not sure if Internet Explorer does support it, but here are the three CSS pseudo-elements you can try:

  • ::selection (works in my Chrome)

  • ::-moz-selection

  • ::-webkit-selection

For example:

p::selection { background:#cc0000; color:#fff; }

Also see http://www.quirksmode.org/css/selection.html

Dev F