当我在Firefox中选择一些文本,然后窗口或iframe失去焦点(例如,选择地址栏)时,即使在CSS中指定了其他颜色,选择也会变成灰色。
如何在Firefox中更改禁用选择的颜色?
我尝试过的
<style>::selection { background-color: green; }</style>
<p>lorem ipsum</p>
Run Code Online (Sandbox Code Playgroud)
编辑:
我想在这里使用的似乎是::inactive-selection,但尚未在firefox中实现。参见https://drafts.csswg.org/css-pseudo-4/#selectordef-inactive-selection
相关错误:https://bugzilla.mozilla.org/show_bug.cgi?id = 706209
有谁知道解决方法?此时,即时通讯正在考虑使用一些JavaScript技巧。任何想法如何做到这一点?
No, you can't
Not on Firefox at least.
Reason I'm answering with a no, is to save both of your time and others who might try to find some solutions / hacks.
Since you already know about the css specification. I might want to add that,
Remember Firefox has it's own version of
::selection,::-moz-selection. It also has it's own version of:window-inactive,:-moz-window-inactive. Unfortunately using these things together doesn't work.Source: CSS Tricks
/* Does work */
::-moz-selection {
background: rgba(255,0,0,0.9);
color: white;
}
/* Doesn't work */
::-moz-selection:-moz-window-inactive {
background: rgba(255,0,0,0.3);
}
/* Nor this */
:-moz-window-inactive::-moz-selection {
background: rgba(255,0,0,0.3);
}
Run Code Online (Sandbox Code Playgroud)
Also, Bugzilla has years old bugs requesting this feature and talking about it's inability to handle inactive selections but no responses on those. Here is a list. Some of them are even 11 years old. I am planning to talk to someone about this and report a new bug myself with some more details, might add their response or the bug number here so that you can get updates.
So, for now I think you shouldn't be looking for some hacks, it'll only waste your time.
Thanks
Update: here is the bug to keep an eye on bugzilla, lets see what the dev team has to say.