why “a:hover MUST come after a:link and a:visited(w3school)”? [duplicate]

。_饼干妹妹 提交于 2019-12-05 10:34:08

Pseudo-classes must be declared in a specific order.

The mnemonic LoVe HAte is always useful for remembering the correct order:

:link
:visited
:hover
:active

Each pseudo-class corresponds to an event which can only happen later in the timeline than the one before.

That is to say:

  1. A link is unvisited before it is visited.

  2. A link is visited before it is hovered over.

  3. A link is hovered over before it is in active use.

The main reason why is because the latter rules execute after the previous ones found in a document in CSS in order, meaning that the behavior of the latter will be executed after all previous rules matched are executed. Therefore, their order does matter in order to avoid overlappings that will affect the behavior of each other.

If for example :link is put after :visited, some behavior of :visited will be overlapped, for example its color showing probably as a normal link despite visited.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!