Hide element on hover of another element

前端 未结 4 778
醉梦人生
醉梦人生 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:12

    You just have to replace the + selector with ~ cause the #hide is not placed after #main

    So your code is:

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

提交回复
热议问题