當類別.parent
的元素被移走時,它會查找類別爲.child
的子元素並將CSS應用於它們。使用CSS查找某個子元素
是否有可能與純粹的CSS實現這個效果?
HTML:
<div class="parent" style="background:red;margin:20px;padding:20px;">
<div class="child" style="background:blue;margin:20px;padding:20px;"></div>
</div>
<div class="parent" style="background:red;margin:20px;padding:20px;">
<div class="child" style="background:blue;margin:20px;padding:20px;"></div>
</div>
的jQuery:
$('.parent').hover(
function() {
$(this).find('.child').css('background','yellow');
},
function() {
$(this).find('.child').css('background','blue');
}
);
完美,謝謝! – UserIsCorrupt
沒問題:)真的很有用的小動作。看到這篇文章更多有用的選擇器:http://css-tricks.com/child-and-siblings-selectors/ –
這是行不通的。內聯樣式將覆蓋它。 – animuson