【问题标题】:Any idea on how to change textarea selection color?关于如何更改 textarea 选择颜色的任何想法?
【发布时间】:2013-02-09 11:32:23
【问题描述】:

我已经尝试过了,但在 textarea 的情况下它不起作用(在 Chrome 和 IE 中):(

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

有没有办法让它成为可能?
CSS 或 jQuery 怎么样?

【问题讨论】:

  • 其他你已经尝试过的,没有办法修改浏览器选择颜色。
  • 嗯,我也这么认为,但让我们看看是否有人有想法..

标签: javascript jquery html css textarea


【解决方案1】:

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

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

见:http://jsfiddle.net/VF4tb/1/

【讨论】:

  • 更改了我的答案,希望对您有所帮助;)
  • 它适用于文本,但不适用于 Chrome 的输入/文本区域...是的,contenteditable 会成功的!
【解决方案2】:

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

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

如此处所示:http://jsfiddle.net/u6CNN/

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

【讨论】:

  • 我认为您正在尝试使用 Firefox 瘦身。所以请检查 Chrome 或 IE
【解决方案3】:

我找到了以下解决方案:

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

【讨论】:

    【解决方案4】:

    如果我理解正确,您想更改文本区域的背景颜色,对吧?

    类似这样的:

    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>
    

    【讨论】:

      猜你喜欢
      • 2010-10-21
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多