问题
Most web browsers provide keyboard shortcuts to interact with the DOM. e.g.:
Tab
shifts the focus to the next focus-able elementAlt + Tab
shifts the focus to the previous focus-able elementEnter
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