我目前有一个包含几个使用相同类的div的div。它看起来像这样,
<div class="deck-content">
<div class="deck-box">TEST
<div class="deck-hidden">
<span class="glyphicon glyphicon-eye-open eye-open" aria-hidden="true"></span>
<span class="glyphicon glyphicon-pencil pencil" aria-hidden="true"></span>
<span class="glyphicon glyphicon-remove remove" aria-hidden="true"></span>
</div>
</div>
<div class="deck-box">TEST
<div class="deck-hidden">
<span class="glyphicon glyphicon-eye-open eye-open" aria-hidden="true"></span>
<span class="glyphicon glyphicon-pencil pencil" aria-hidden="true"></span>
<span class="glyphicon glyphicon-remove remove" aria-hidden="true"></span>
</div>
</div>
<div class="deck-box">TEST
<div class="deck-hidden">
<span class="glyphicon glyphicon-eye-open eye-open" aria-hidden="true"></span>
<span class="glyphicon glyphicon-pencil pencil" aria-hidden="true"></span>
<span class="glyphicon glyphicon-remove remove" aria-hidden="true"></span>
</div>
</div>
</div>
当我将鼠标悬停在类名为deck-box
的div上时,我希望类名deck-hidden
的div可见。
问题是我不知道会有多少deck-box
个div。所以我不能给他们所有不同的ID名称。
如何将鼠标悬停在deck-box
上并让其各自的孩子deck-hidden
可见?
答案 0 :(得分:4)
您可以使用
.deck-box:hover .deck-hidden {
display: block;
}
答案 1 :(得分:1)
$('div.deck-box').hover(function(){
$(this).children('div').show();
}, function(){
$(this).children('div').hide();
})
答案 2 :(得分:0)
来自Syahrul的回答&#39;是正确的方法。但是代表类名有一个错误,它不会像你期望的那样工作。 &#39;。&#39;在子类名称之前丢失。 正确的答案是,
.deck-hidden {
display: none;
}
.deck-box:hover .deck-hidden {
display: block;
}