关于如何改变textarea选择颜色的任何想法?

时间:2013-02-09 11:32:24

标签: javascript jquery html css textarea

我试过这个,但在textarea的情况下它不会起作用(在Chrome和IE中):(

::-moz-selection {
  background: #b3d4fc;
  text-shadow: none;
}
::selection {
  background: #b3d4fc;
  text-shadow: none;
}

有没有办法使它成为可能?
CSS还是jQuery怎么样?

4 个答案:

答案 0 :(得分:4)

仅在Firefox(和Safari?)中支持。

你可以做一个解决方法。而不是textarea使用div与contenteditable。

请参阅:http://jsfiddle.net/VF4tb/1/

答案 1 :(得分:1)

您是否尝试更改textarea的背景颜色或仅更改其中文字的颜色?如果是后者,那么这就是你想要的:

::-moz-selection {
  color: #b3d4fc;
  text-shadow: none;
}
::selection {
  color: #b3d4fc;
  text-shadow: none;
}

如下所示:http://jsfiddle.net/u6CNN/

顺便说一句,您也可以指定background-color

答案 2 :(得分:0)

我找到了以下解决方案:

.YourForm textarea:focus {
  background-color: #000;
}

答案 3 :(得分:-1)

如果我理解正确你想要改变textarea的背景颜色,对吧?

类似的东西:

textarea{
    /* Change the color of the typed text in the textarea */
    color: #CCC;

    /* Change the background color of the actual textarea */
    background-color: #000;
}

或与班级:

CSS->

.classname{
    /* Change the color of the typed text in the textarea */
    color: #CCC;

    /* Change the background color of the actual textarea */
    background-color: #000;
}

HTML->

<textarea class="classname">
</textarea>