To ensure the active state is activated while the user hovers over the button, it is important for the :hover
selector to be placed before the :active
selector in the code.
According to information from https://developer.mozilla.org/en-US/docs/Web/CSS/:active:
The styles assigned by the :active pseudo-class can be overridden by subsequent link-related pseudo-classes (:link, :hover, or :visited) with equal or greater specificity. To ensure proper styling of links, follow the LVHA-order: :link — :visited — :hover — :active.
Although the accepted answer mentioned the importance of placing :active
after :link
and :visited
, it did not explicitly state the need for :active
to come after :hover
(which was already the case in the example provided). However, this aspect was not immediately clear to me, prompting me to share this response for others encountering similar confusion due to the positioning of the :hover
and :active
selectors.
Additionally, I believe adhering to the LVHA order is a useful guideline in addressing this issue.