gpt4 book ai didi

css - 这个伪类排序不冲突吗?

转载 作者:行者123 更新时间:2023-11-28 18:53:20 24 4
gpt4 key购买 nike

我知道伪类必须按顺序排列,以免相互冲突。 (双重“按顺序”意在)

问题是我读到 CSS 从右到左读取(在找到匹配项时),这让我对此产生了疑问:

a{
color:blue;
text-decoration:none;
}

a:hover,a:focus{
text-decoration:underline;
}

应该是a:focus,a:hover还是我现在这样就好了?

最佳答案

在这种情况下,这无关紧要,因为它们不能同时触发...考虑到 :hover 用于用鼠标和 触发的链接事件: focus 用于通过键盘触发的链接事件。

但是,读这个

The :link and :visited pseudo-classes should generally come first. Next should be :focus and :hover—they’re specified now so that they override and apply to both visited and unvisited links. If :focus precedes :hover, the hover effect will apply to links with keyboard input focus. The :active pseudo-class should always come last, since we usually want to indicate clearly any links that have been activated.

来自这里:http://reference.sitepoint.com/css/pseudoclasses

在这种情况下,我认为理想的是

a:link{
}

a:visited{
}

a:focus, a:hover{
}

a:active{
}

关于css - 这个伪类排序不冲突吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8675760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com