How to display and hide a div with CSS?

后端 未结 4 1344
夕颜
夕颜 2020-12-01 00:48

In my script there are three divs. I want to display div with class=\"ab\" when I hover on first line and display div with class=\"abc\", when hove

4条回答
  •  借酒劲吻你
    2020-12-01 01:29

    You need

    .abc,.ab {
        display: none;
    }
    
    #f:hover ~ .ab {
        display: block;
    }
    
    #s:hover ~ .abc {
        display: block;
    }
    
    #s:hover ~ .a,
    #f:hover ~ .a{
        display: none;
    }
    

    Updated demo at http://jsfiddle.net/gaby/n5fzB/2/


    The problem in your original CSS was that the , in css selectors starts a completely new selector. it is not combined.. so #f:hover ~ .abc,.a means #f:hover ~ .abc and .a. You set that to display:none so it was always set to be hidden for all .a elements.

提交回复
热议问题