为什么网络浏览器在通过Enter键激活时不应用CSS:active状态? [英] Why do web browsers don't apply the CSS :active state on activation by enter key?

查看:81
本文介绍了为什么网络浏览器在通过Enter键激活时不应用CSS:active状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数Web浏览器都提供键盘快捷方式来与DOM交互。 例如:

Most web browsers provide keyboard shortcuts to interact with the DOM. e.g.:

Tab 将焦点转移到下一个可聚焦的元素

Alt + Tab 将焦点移到上一个可聚焦的元素

Enter 激活当前关注的元素

Tab shifts the focus to the next focus-able element
Alt + Tab shifts the focus to the previous focus-able element
Enter activates the currently focused element

我现在发现,许多流行的浏览器(Firefox,Chrome,Safari,Internet Explorer)未应用CSS <如果通过按 Enter 键激活元素,则code>:active 伪类。

What I have now figured out is that many popular browsers (Firefox, Chrome, Safari, Internet Explorer) don't apply the CSS :active pseudo-class if an element gets activated by pressing the Enter key.

为什么会这样?

我认为这具有误导性,因为您好像没有触发按钮。

I think it is misleading because it looks like you don't trigger the buttons; although you actually do.

推荐答案

根据 CSS选择器规范


:active伪类在用户激活元素
时适用。例如,在用户按下鼠标
按钮并释放它的时间之间。 [...]

The :active pseudo-class applies while an element is being activated by the user. For example, between the times the user presses the mouse button and releases it. [...]

因此,标准明确要求:active 当用户单击元素时应用。没有别的了,所以这不是浏览器的问题,这是缺少标准的结果。

So the standard explicitly says that :active should be applied when a user clicks on the element. There is nothing else, so this is not a problem of the browsers, it is a result of a missing standard.

这篇关于为什么网络浏览器在通过Enter键激活时不应用CSS:active状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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