There is a hack to make work :focus
pseudoclass for div
elements: adding to div
tabindex
. Like this:
.testFocus:focus{
background: red;
}
<div class="testFocus" tabindex="0">awesomeDiv</div>
Is this behavior specified somewhere in W3C documents (where?) or is it just a non-documented hack?
"This behavior" consists of:
div
element is not focusable by default.div
element withtabindex
is focusable.
tabindex
is one of the global attributes. This means it can be specified on all HTML elements.0
is a valid value (see "If the value is a zero" under the definition oftabindex
).So your HTML is fine.