Selecting all links except hovered one CSS only

后端 未结 3 1735
轮回少年
轮回少年 2021-01-22 14:15

I\'m trying to make a CSS selector that matches all links except the hovered one. Naturally I though of using the ~ operator to catch around elements:



        
3条回答
  •  花落未央
    2021-01-22 14:39

    You cant do what you are explicitly after, without using JavaScript due to the way CSS selectors work based on DOM hierarchy and their limited potential for traversal.

    However, given what I imagine you are trying to achieve, why not apply the hover to the parent element and exclude the currently hovered a?

    Demo Fiddle

    (and an alternative)

    div:hover a:not(:hover){
        color:red;
    }
    

提交回复
热议问题