更改父div的背景悬停 [英] change background of parent div on hover

查看:87
本文介绍了更改父div的背景悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

 < div class =thumb_image_holder_orange> 
< img src =http://dummyimage.com/114x64/000/fff.png/>
< / div>

图片在div的中间位置,如何在悬停时更改div的背景



我只知道如何在悬停在div上时更改图像属性。



谢谢!

解决方案

你不能。 CSS没有任何方法选择父元素:



http://snook.ca/archives/html_and_css/css-parent-selectors


不希望使用jQuery,但
不介意太多。


使用: http://jsfiddle.net/KHc6X/

  $('。thumb_image_holder_orange &img')。hover(function(){
$(this).parent()。toggleClass('hover');
})
/ pre>

I have this code:

<div class="thumb_image_holder_orange">
    <img src="http://dummyimage.com/114x64/000/fff.png" />
</div>

The image is centred in the middle of the div, how can I change the div's background when I hover over the image?

I only know how to change the image properties when I hover over the div.

Would prefer not to use jQuery, but don't mind too much.

Thanks!

解决方案

You can't. CSS does not have any way to select the "parent element":

http://snook.ca/archives/html_and_css/css-parent-selectors

Would prefer not to use jQuery, but don't mind too much.

Use: http://jsfiddle.net/KHc6X/

$('.thumb_image_holder_orange > img').hover(function(){
    $(this).parent().toggleClass('hover');
})

这篇关于更改父div的背景悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆