【发布时间】:2018-07-13 18:27:15
【问题描述】:
目前我正在尝试了解 :active 和 :focus 伪类之间的关系。
这是我的例子:
<a href="http://google.com" target="_blank">Google</a>
<style>
a:link { color: rgb(0, 138, 206); } /* Blue */
a:visited { color: rgb(180, 14, 180); } /* Violet */
a:active { color: yellow; }
a:focus { color: green; }
</style>
如果您单击该链接,您会看到它的颜色从蓝色/紫色变为绿色。您不会看到活动状态,即黄色。
然后,让我们尝试从我们的 CSS 中删除 a:focus:
<style>
a:link { color: rgb(0, 138, 206); } /* Blue */
a:visited { color: rgb(180, 14, 180); } /* Violet */
a:active { color: yellow; }
</style>
现在,当我们点击链接时,它的活动状态是成功可见的。即,链接的颜色从蓝色/紫色变为黄色,持续 1 秒。
我不问:active 和:focus 伪类之间的区别——当然,我知道。
我的问题是为什么我们在第一个示例中看不到 :active 状态(黄色)。
【问题讨论】:
标签: html css hyperlink css-selectors pseudo-class