Why does the hover pseudo-class override the active pseudo-class

后端 未结 7 1423
不思量自难忘°
不思量自难忘° 2020-12-30 01:17

The title basically says it all.

Suppose I have an element which I want to change color on :hover, but while clicked, I want it to swit

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 02:07

    yes this is expected behavior,

    lets take a look at another example. just adding two classes,

    • item
    • item
    • item
    • item
    • item

    here the class first also comes together with the class item. but if we declare our css in the wrong order that would not give the wanted behavior

    .first { background: blue; }
    .item { background: red; }
    

    as you can see, the last matching selector will be used. it is the same as your example, no mather what is more logic, the 2 pseudo-classes are concidered equal, thus the same rules apply the last matching defenition wins.

    edit

    pseudoclasses are equals, it is the one defined last that wins! here is a jsFiddle that proves my point :link defined after :hover, :link wins (test) so, your statement of :hover overriding :link is wrong, its just the same like with :active, its all about the order.

提交回复
热议问题