在选择时更改边框颜色 [英] Changing border-color on selection

查看:97
本文介绍了在选择时更改边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 :: selection :: - moz-selection 假元素。我已经成功地改变了选择的颜色和背景与这两条规则:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆