是否在某处指定了 CSS 的 tabindex hack :focus? [英] Is tabindex hack for CSS :focus specified somewhere?

查看:74
本文介绍了是否在某处指定了 CSS 的 tabindex hack :focus?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个技巧可以使 :focus 伪类用于 div 元素:添加到 div tabindex.像这样:

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>

这种行为是在 W3C 文档的某处(在哪里?)中指定的,还是只是一个未记录的黑客行为?

Is this behavior specified somewhere in W3C documents (where?) or is it just a non-documented hack?

这种行为"包括:

  1. div 元素默认不可聚焦.
  2. 带有 tabindex
  3. div 元素是可聚焦的.
  1. div element is not focusable by default.
  2. div element with tabindex is focusable.

推荐答案

tabindex全局属性.这意味着它可以在所有 HTML 元素上指定.

tabindex is one of the global attributes. This means it can be specified on all HTML elements.

0 是有效值(请参阅 tabindex 的定义).

0 is a valid value (see "If the value is a zero" under the definition of tabindex).

所以你的 HTML 没问题.

So your HTML is fine.

这篇关于是否在某处指定了 CSS 的 tabindex hack :focus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆