:focus 伪类以及何时应用 [英] The :focus pseudo-class and when it is applied

查看:18
本文介绍了:focus 伪类以及何时应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:focus 选择器用于设置一般意义上具有焦点的元素的样式.但是考虑到鼠标按下或触摸等情况,它究竟是什么时候应用的?作为 Web 开发人员,我如何控制它以保持一致?

The :focus selector is used to style elements that have focus in the general sense. But when exactly is it applied, considering cases like mouse down or touch? And how as a web developer can I control it to be consistent?

例如在 Stack Overflow 上,如果我将鼠标放在其中一个链接上,但没有激活,通过在释放之前将鼠标移开,链接将获得键盘焦点(如按 Tab 键所见,焦点转到下一个链接).但是,即使它具有焦点,它也不会获得 :focus 样式.如果我选择一个链接,我会得到 :focus 大纲样式.

e.g. here on Stack Overflow, if I mouse down on one of the links, but do not activate, by moving the mouse off before releasing, the link gets keyboard focus (as seen by then pressing tab, the focus goes to the next link). However it does not get the :focus style even though it has focus. If I tab onto a link though, I get the :focus outline style.

但是在我正在处理的一个网站上,按下鼠标会立即为我提供 :focus 样式,因此必须有一些微妙的细节.

But on one of the websites I am working on, the mouse down gives me the :focus style straight away, so there must be some subtle detail.

在这个片段中,Chrome 中的 <a>

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