Tutorial :Can I do away with this highlighting in HTML?



Question:

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?


Solution:1

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


Solution:2

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...)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »