Jul
21

Change the background colour of selected text

By Sam  //  All browsers, CSS 3.0  //  No Comments

So, you want to override the browser’s default selected text colour? A simple bit of CSS will allow you to change it in most modern browsers (Firefox, Safari, Opera) while not causing any problems for users with IE.

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

You’ll see I’ve changed the colour of the text there as well so that it is still legible when the background is black.

I probably don’t need to point out that you can, of course, apply this to any text element and have different colours for headings, links, etc.

Leave a comment

Sponsored links