Changing the highlight color when selecting text in an HTML text input

后端 未结 10 1096
有刺的猬
有刺的猬 2020-11-30 00:07

I\'ve been looking for this throughout the web and can\'t even find anyone else even asking this, let alone a solution...

Is there a way to change the color of the h

10条回答
  •  情话喂你
    2020-11-30 01:08

    @ Mike Eng,

    On selecting the text background color, text color can be changed with the help of ::selection, note that ::selection works in in chrome, to make that work in firefox based browsers try this one ::-moz-selection

    Try the following snippet of code in reset.css or the css page where exactly you want to apply the effect.

    ::selection{
       //Works only for the chrome browsers
       background-color: #CFCFCF; //This turns the background color to Gray
       color: #000; // This turns the selected font color to Black
    }
    
    ::-moz-selection{
       //Works for the firefox based browsers
       background-color: #CFCFCF; //This turns the background color to Gray
       color: #000; // This turns the selected font color to Black
    }
    

    The above code will work even in the input boxes too.

提交回复
热议问题