Use :hover to modify the css of another class?

前端 未结 5 694
旧时难觅i
旧时难觅i 2020-11-29 01:44

Is there a way to modify the css for one class when hovering on an element from another class using only css ?

Something like:

.item:hover .wrapper {         


        
5条回答
  •  暖寄归人
    2020-11-29 02:15

    Provided .wrapper is inside .item, and provided you're either not in IE 6 or .item is an a tag, the CSS you have should work just fine. Do you have evidence to suggest it isn't?

    EDIT:

    CSS alone can't affect something not contained within it. To make this happen, format your menu like so:

    and your CSS like this:

    .menu .menu {
        display: none;
    }
    
    .menu .menuitem:hover .menu {
        display: block;
        float: left;
        // likely need to set top & left
    }
    

提交回复
热议问题