sawa
sawa

Reputation: 168269

Setting for selected text

I am trying to override the default setting for selection. I did

::selection{
  background: grey;
}

and it looks like that takes effect when the window is not focused, but when it is focused, it does not have effect and the default color appears. It is not working. What is the correct way to do this so that is has effect irrespective of the focus?

Edit I think I was wrong. I want to change the color of the selected text in <input> tag. How can I do that?

Upvotes: 0

Views: 50

Answers (3)

Mr. Alien
Mr. Alien

Reputation: 157424

It is the default browser behavior which you cannot change, when window is not focused, the selected color changes to grey, may be it denotes that the text cannot be copied (kinda disabled selection), so we cannot control that color

enter image description here


Example 2

enter image description here

Upvotes: 1

Rab
Rab

Reputation: 35582

Should Work fine, See this demo. the problem seems to be due to something else

::selection
{
background: grey;
}
::-moz-selection
{
background: grey;
}

Upvotes: 1

Blender
Blender

Reputation: 298582

You're probably using Firefox, which needs the -moz prefix:

::selection {
    color: fireBrick;
}

::-moz-selection {
    color: fireBrick;
}

Demo: http://jsfiddle.net/N4AUY/

Note that you cannot group these together. One of these won't work, so the whole rule block breaks.

Upvotes: 1

Related Questions