Show :after when hovering over the parent element via CSS

后端 未结 2 1335
栀梦
栀梦 2020-12-17 20:45

Is it possible to display:block; the :after pseudo-element when I hover over the parent element itself?

#myDiv{
   position:relativ         


        
相关标签:
2条回答
  • 2020-12-17 20:53

    You are trying to reference the same element, so you don't need to duplicate the ID selector. No need to use the child selector either, just use:

    #myDiv:hover:after {
        display: block;
    }
    

    jsFiddle Demo

    0 讨论(0)
  • 2020-12-17 21:13

    Change it to #myDiv:hover::after

    You can use either :after or ::after but in the selectors module (3) it states that the latter is now intended to be used to distinguish them from pseudo-classes

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