CSS :hover effect not working when I set an ID to the paragraph

后端 未结 1 909
谎友^
谎友^ 2020-12-06 18:14

I have the following css3 transition with ease effect:

HTML


                      
相关标签:
1条回答
  • 2020-12-06 18:51

    The problem is that the selector handling your :hover behavior has a lower Specificity than the rule for the default behavior (p#id selector).

    Changing this

    .button:hover .top {
    

    to this

    .button:hover #myId.top {
    

    will solve the problem: Running example

    You can also apply an id to a parent object (lets' say <div id="container">), and then use

    #container .button:hover .top {
    

    A must-read: Specifics on CSS Specificity

    Examples:

    enter image description here

    enter image description here

    0 讨论(0)
提交回复
热议问题