什么是-webkit-focus-ring-color?
我想将 webkit 中聚焦输入框的 outline
效果重现到非 webkit 浏览器。我在此处找到了webkit 中使用的默认 CSS。感兴趣的行是:
:focus {
outline: auto 5px -webkit-focus-ring-color
}
我尝试在整个代码中搜索定义 -webkit-focus-ring-color
此处 但无法在任何地方找到它。
I want to reproduce the outline
effect for focused input boxes in webkit to non-webkit browsers. I found here the default CSS used in webkit. The lines of interest are:
:focus {
outline: auto 5px -webkit-focus-ring-color
}
I tried making a search in the whole code for the definition -webkit-focus-ring-color
here but could not find it anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
-webkit-focus-ring-color
在 WebKit 代码库中定义为每个RenderTheme
类中的focusRingColor
。这项工作是在 2009 年 6 月作为 Jeremy Moskovich 变更集的一部分进行的。例如,默认的 Mac 主题(Safari 使用)在
RenderThemeMac.mm
(以迂回方式)为:(苹果非常该属性的简单文档可在线获取)。
Mac 有一个覆盖值(称为 WebCore::oldAquaFocusRingColor)用于测试(据我所知,它是为了让代码能够在浏览器渲染和参考之间进行比较)图形;使用 WebCore::usesTestModeFocusRingColor 进行切换)。它在
ColorMac.mm
< 中定义/a> 如下(显然映射到Color(125, 173, 217)
):Chromium/Chrome 定义
RenderThemeChromiumSkia.cpp
为:默认颜色 (在
RenderTheme.h
)是纯黑色:-webkit-focus-ring-color
is defined in the WebKit codebase asfocusRingColor
in eachRenderTheme
class. That work was performed in June 2009 as part of this changeset by Jeremy Moskovich.For instance, the default Mac theme (used by Safari) defines the colour in
RenderThemeMac.mm
(in a roundabout way) as:(Apple's very light documentation of that property is available online).
There is an override value for the Mac (called
WebCore::oldAquaFocusRingColor
) to be used for testing (near as I can tell it's for the code to be able to perform comparison between the browser rendering and a reference graphic; it is toggled usingWebCore::usesTestModeFocusRingColor
). It's defined inColorMac.mm
as the following (which apparently maps toColor(125, 173, 217)
):Chromium/Chrome defines the colour in
RenderThemeChromiumSkia.cpp
as:The default colour (specified in
RenderTheme.h
) is pure black:-webkit-focus-ring-color
在 Firefox 中不起作用。不过,您可以使用系统颜色Highlight
作为替代。另请参阅此网站,了解为什么重置
outline
样式通常是一个坏主意。-webkit-focus-ring-color
does not work in Firefox. You can use the system colorHighlight
as a replacement though.Also see this site on why resetting
outline
styles is usually a bad idea.使用这个jsFiddle。我在 Windows 7 上的 Chrome 14 中得到了
rgb(229, 151, 0)
。Use this jsFiddle. I got
rgb(229, 151, 0)
in Chrome 14 on Windows 7.前言:
在 Mac 上使用 Chrome,在使用正常浏览器模式时,我会看到蓝色的轮廓颜色。当我使用设备视图时,我得到黄色/金色轮廓颜色。
不知道为什么会改变——实际上非常令人困惑。请参阅下面的示例。
FWIW:
Using Chrome on a Mac, I get a blue outline color when using normal browser mode. When I use the device view, I get a yellow/golden outline color.
Not sure why it changes - was actually very confusing. See examples below.
以下代码尝试找到最接近系统颜色的解决方案:
The following code tries to find the closest solution to the system colors:
如今,
revert
值具有良好的浏览器支持(耶!),用于回滚到默认的UA样式,这里是我的2020 “请让我有轮廓”片段(通常伴随!important
声明):或者如果您希望对
outline
的第一个实例使用普通属性:Nowadays, the
revert
value has good browser support (yay!), which is used to roll back to the default UA styles, here's my 2020 "please let me have outlines" snippet (usually accompanied with!important
declarations):Or if you wish to use longhand properties for the first instance of
outline
: