在悬停时更改父div的背景

472*_*084 10 css jquery

我有这个代码:

<div class="thumb_image_holder_orange">
    <img src="http://dummyimage.com/114x64/000/fff.png" />
</div>
Run Code Online (Sandbox Code Playgroud)

图像位于div的中间,当我将鼠标悬停在图像上时,如何更改div的背景?

我只知道当我将鼠标悬停在div上时如何更改图像属性.

宁愿不使用jQuery,但不要太在意.

谢谢!

thi*_*dot 13

你不能.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');
})
Run Code Online (Sandbox Code Playgroud)


ale*_*lex 5

CSS选择器无法提升,因此您需要使用JavaScript.

你标记它所以这是一个jQuery答案.

$('.thumb_image_holder_orange img').mouseover(function() {
    $(this).parent().css('backgroundImage', 'url(/whatever/you/want.png)');
});
Run Code Online (Sandbox Code Playgroud)