CSS :: child set to change color on parent hover, but changes also when hovered itself

前端 未结 2 547
庸人自扰
庸人自扰 2020-12-08 13:00
2条回答
  •  醉酒成梦
    2020-12-08 13:30

    If you don't care about supporting old browsers, you can use :not() to exclude that element:

    .parent:hover span:not(:hover) {
        border: 10px solid red;
    }
    

    Demo: http://jsfiddle.net/vz9A9/1/

    If you do want to support them, the I guess you'll have to either use JavaScript or override the CSS properties again:

    .parent span:hover {
        border: 10px solid green;
    }
    

提交回复
热议问题