This selector performs the trick:
li[tabindex='1']:focus ~ li[tabindex='1'], li[tabindex='1']:focus { background: black; color: white; }
Here is an example.
He only chooses when you focus on the first, though.
This only works in CSS3, since we use a common selector.
When the first is focused, it selects the second with the same tabindex and adds the background. Second li[tabindex='1']:focus - apply the background to the current focused one.
A common selector can only select the following items with the same parent. Unfortunately, CSS cannot travel the DOM. For this reason, the only way to make it work in the opposite direction is to use Javascript.
source share