Why do web browsers don't apply the CSS :active state on activation by enter key?

江枫思渺然 提交于 2020-03-23 07:04:29

问题


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

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

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.

Why is this so?

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


回答1:


https://developer.mozilla.org/en-US/docs/Web/CSS/%3Aactive

According to mozilla documentation, the active pseudo class is related to the mouse and the tab key. But there's no mention of the Enter key.




回答2:


According to the CSS Selectors specification:

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. [...]

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.



来源:https://stackoverflow.com/questions/32908180/why-do-web-browsers-dont-apply-the-css-active-state-on-activation-by-enter-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!