Hide element on hover of another element

前端 未结 4 768
醉梦人生
醉梦人生 2021-01-19 23:21

I know it can be done in JavaScript, however I am looking for solution in CSS.

I have three divs.

  • div#hide should be visible
4条回答
  •  醉酒成梦
    2021-01-20 00:18

    You've to use tilda '~' for this case.

    The difference between + and ~ is that ~ matches all following siblings regardless of their proximity from the first element, as long as they both share the same parent.

        #show {display:none}
        #main:hover + #show { display:block }
        #main:hover ~ #hide { display:none }
    

提交回复
热议问题