Can I use img:hover to get another element?

前端 未结 5 1514
青春惊慌失措
青春惊慌失措 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:08

    As img cannot hold any other nested tag, I assume you are targeting the adjacent element, you can use adjacent selector here using +

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

    The above selector will select the element next to img tag when the image is hovered.

    Note: Above selector will work only if you've your markup like

    But will fail if you've markup like

提交回复
热议问题