Can I use img:hover to get another element?

前端 未结 5 1557
青春惊慌失措
青春惊慌失措 2021-01-25 10:33

So is it possible to make this work

#element img:hover #otherelement {...}

like

#element:hover #otherelement {...}
5条回答
  •  独厮守ぢ
    2021-01-25 11:09

    You can use the :hover pseudo class on any element. There are considerations to be made in regards to cross-browser. You can use a polyfill like Selectivizr for that, though.

    As for your question, you might want to consider targeting a shared ancestor for both elements you are trying to target with the hover and apply your styles that way.

提交回复
热议问题