更改父div的背景悬停 [英] change background of parent div on hover
问题描述
我有这个代码:
< 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(){
/ pre>
$(this).parent()。toggleClass('hover');
})
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屋!