我有这个代码:
<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,但不要太在意.
$('.thumb_image_holder_orange > img').hover(function(){
$(this).parent().toggleClass('hover');
})
Run Code Online (Sandbox Code Playgroud)
CSS选择器无法提升,因此您需要使用JavaScript.
你标记它jquery所以这是一个jQuery答案.
$('.thumb_image_holder_orange img').mouseover(function() {
$(this).parent().css('backgroundImage', 'url(/whatever/you/want.png)');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17277 次 |
| 最近记录: |