2

I can disable the content selection of any webpage using the code below which works well.

<div 
 style="-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;" 
 unselectable="on"
 onselectstart="return false;" 
 onmousedown="return false;">
    Cannot select me
</div>

Image showing text selection is given below :

enter image description here

My question is:

  • How can i disable blue background and highlight only the text that i select from any webpage?

Second part of the question moved to ux.stackexchange.

Community
  • 1
  • 1
Tharif
  • 13,794
  • 9
  • 55
  • 77

1 Answers1

3

The ::selection CSS pseudo-element will help you, apply it to body or html like;

body::selection {
    background-color:transparent;
    color:#0000FF;
}

DEMO

glend
  • 1,592
  • 1
  • 17
  • 36
  • I still need to add with vendor prefix `-moz-selection` for Firefox browser. Not sure why. – m4n0 Jul 02 '15 at 10:47