What is the difference between :focus and :active?(:focus 和 :active 有什么区别?)
问题描述
:focus
和 :active
伪类有什么区别?
What is the difference between the :focus
and :active
pseudo-classes?
推荐答案
:focus
和 :active
是两种不同的状态.
:focus
and :active
are two different states.
:focus
表示当前选择元素接收输入时的状态,:active
表示元素当前被用户激活时的状态.
:focus
represents the state when the element is currently selected to receive input and:active
represents the state when the element is currently being activated by the user.
例如,假设我们有一个 <button>
.<button>
将没有任何状态开始.它只是存在.如果我们使用 Tab 将焦点"赋予 ,它现在进入其
:focus
状态.如果然后单击(或按 space),则使按钮进入其 (:active
) 状态.
For example let's say we have a <button>
. The <button>
will not have any state to begin with. It just exists. If we use Tab to give "focus" to the <button>
, it now enters its :focus
state. If you then click (or press space), you then make the button enter its (:active
) state.
关于那个注意,当你点击一个元素时,你给它焦点,这也培养了 :focus
和 :active
相同的错觉.它们不一样.当点击按钮时,按钮处于:focus:active
状态.
On that note, when you click on an element, you give it focus, which also cultivates the illusion that :focus
and :active
are the same. They are not the same. When clicked the button is in :focus:active
state.
一个例子:
<style type="text/css">
button { font-weight: normal; color: black; }
button:focus { color: red; }
button:active { font-weight: bold; }
</style>
<button>
When clicked, my text turns red AND bold!<br />
But not when focused only,<br />
where my text just turns red
</button>
jsfiddle
这篇关于:focus 和 :active 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为::focus 和 :active 有什么区别?


基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01