Use :hover to modify the css of another class?

前端 未结 5 698
旧时难觅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:38

    It's not possible in CSS at the moment, unless you want to select a child or sibling element (trivial and described in other answers here).

    For all other cases you'll need JavaScript. jQuery and frameworks like Angular can tackle this problem with relative ease.

    [Edit]

    With the new CSS (4) selector :has(), you'll be able to target parent elements/classes, making a CSS-Only solution viable in the near future!

提交回复
热议问题