WCAG 2.0 also recommends using :focus when :hover used for link elements to support keyboard navigation. This works well for link elements, but there are several differences between them.
- any element can have a state
:hover , but only very little can be focused - When you hover over an element, you also hover over all of its parent elements. This does not apply to focus.
This question is strictly about css. Is there a way to simulate :hover behavior (as described above) to navigate the keyboard? Or are there any good reasons why you would not want to?
To make this clearer, an example is provided:
HTML:
<div id="box"> foo bar <a href="#">click me</a> </div>
CSS
#box { opacity: 0.3; } #box:hover { opacity: 1; } #box a:focus { opacity: 1; }
When using the mouse, I will hover over the link element before using it. Since the state :hover extends upwards, #box will be completely opaque.
When using the keyboard, I will focus the link element before using it. Since the :focus state does not extend upwards, #box will not be fully opaque.
css accessibility hover
tobib
source share