SELECT HTML ELEMENTS BY USER SELECTION

You can alter the user-selection highlight — what the user sees when selecting text — using new CSS3 pseudo-elements called ::selection and ::-mozselection. The first syntax is understood by Chrome and Safari and Opera 9.5. The second syntax is supported by Firefox 3.6 and later.

No additional arguments or elements can be specified in the selector, but the CSS declaration is limited to only color-based CSS stylizing. Therefore, background images, borders, font, or text-based stylizing will be ignored:

::selection {
  background-color: #f00;
  color: #fff;
}
::-moz-selection {
   background-color: #f00;
   color: #fff;
}

In these example CSS rules, the background is changed to red, and the text color to white. Note ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.