CSS3 - 如何在 Chrome 中的文本区域和输入中设置所选文本的样式?
编辑:正如 @geca 在评论中指出的,这是一个已知的 WebKit bug。希望它能尽快修复!
::selection
伪元素允许设置所选文本的样式。这按预期工作,但不适用于 Google Chrome 15 中的文本区域和输入。 (我不确定这是否是 webkit 或 chrome 问题,因为我无法在 Linux 上使用 Safari。)
这是一个演示此问题的 jsfiddle: http://jsfiddle.net/J5N7K/2/ 段落中选定的文本具有应有的样式。文本区域中选定的文本和输入不是。 (但它是在 Firefox 上。)
我是否做错了什么,或者现在无法在 Chrome 上设置它的样式?
EDIT: As @geca noted in the comments, this is a known WebKit bug. Let's hope it gets fixed soon!
The ::selection
pseudo-element allows one to style the selected text. This works as expected but not for textareas and inputs in Google Chrome 15.
(I'm not sure if it's a webkit or chrome issue since I can't use Safari on Linux.)
Here's a jsfiddle demonstrating this issue: http://jsfiddle.net/J5N7K/2/
The selected text at the pargraph is styled as it should be. The selected text in the textarea and input isn't. (But it is at Firefox.)
Am I doing something wrong or is it just not possible to style it at Chrome right now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
带有
contenteditable
的是一个选项吗?函数仅列出大多数内容的
演示: http://jsfiddle.net/ThinkingStiff/FcCgA/
HTML:
CSS:
输出 (Chrome) :
Is a
<div>
withcontenteditable
an option? Functions just list a<textarea>
for most things.Demo: http://jsfiddle.net/ThinkingStiff/FcCgA/
HTML:
CSS:
Output (Chrome):
这是一个已知的 WebKit 错误。抱歉,到目前为止还没有解决方案:)
更新:WebKit 错误已于 2014 年 10 月 13 日修复。
This is a known WebKit bug. Sorry, no solution thus far :)
Update: the WebKit bug was fixed on 10/13/2014.
您是否有可能不使用 CSS 伪元素而使用一些 jQuery。
看看这个http://jsfiddle.net/J5N7K/6/。
如果您不明白 jQuery,请随时询问。
Is there any chance that instead of using CSS pseudo-element you can use some jQuery.
take a look at this http://jsfiddle.net/J5N7K/6/.
if you don't understand the jQuery feel free to ask about it.
使用这个:
use this :