在选择时更改边框颜色 [英] Changing border-color on selection
问题描述
我尝试使用 :: selection
和 :: - moz-selection $ c $修改默认选择样式c>假元素。我已经成功地改变了选择的颜色和背景与这两条规则:
I'm trying to modify the default selection styles by using the ::selection
and ::-moz-selection
pseudoelements. I've successfully changed the selection color and background with these two rules:
::-moz-selection{ background: #444; color:#fff; text-shadow: none; }
::selection { background:#444; color:#fff; text-shadow: none; }
但是,我还需要更改 border-color
为白色选择链接。我想这个CSS来实现:
However, I also need to change the border-color
to white on selection for links. I'm trying to accomplish this with this CSS:
a::-moz-selection { border-color:#FFF;}
a::selection {border-color:#FFF; }
即使我添加了!important
重写,Safari不会为边框颜色设置样式。
Even when I add an !important
override, Safari won't style the border color.
我缺少什么?为什么我不能更改链接的边框颜色
的选择?
What am I missing? Why can't I change a link's border-color
on selection?
推荐答案
您不能为文本选择定义 border
样式。
You can't define border
styles for text selections.
尝试定义纲要
,而不是(这将是允许的属性之一作为的老规格和 SitePoint参考):
Try defining an outline
instead (it was going to be one of the allowed properties as stated in the old spec and the SitePoint Reference):
a::-moz-selection { outline: 1px solid #fff; }
a::selection { outline: 1px solid #fff; }
如果这不起作用,恐怕浏览器不支持大纲 :: selection
。
If that doesn't work, then I'm afraid the browser just doesn't support outlines on ::selection
.
请记住, ::选择
已搬离选择器的SPEC ,用CSS水平其余3仍然是草稿,因此您不能依赖浏览器正确/完全实现它。
Remember that ::selection
has been move out of the Selectors spec, with the rest of CSS level 3 still being a draft, so you can't rely on browsers implementing it correctly/completely just yet.
这篇关于在选择时更改边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!