我在实现以下代码时遇到问题。我想通过悬停另一个元素来影响元素。这是我的代码。
<div class="banner">
<div class="first">
<a href="Http://www.nytimes.com"><b>T</b></a>
</div>
<div class="second">
<ul class="navigation" style="; border-radius: 10px; ">
<p style="display: inline" id="hp">
<a href="http://www.nytimes.com">Go Back To Home</a>
</p>
<li><a href="http://www.somelink.com">Women Fashin</a></li>
<li><a href="http://www.somelink.com">Men fashion</a></li>
</ul>
</div>
</div>
我希望通过悬停#hp
来影响.first
。我怎样才能达到这个结果?
答案 0 :(得分:5)
您可以使用General sibling selector
~
.first:hover ~ .second .navigation #hp a {
color: red;
}
<div class="banner">
<div class="first">
<a href="Http://www.nytimes.com"><b>T</b></a>
</div>
<div class="second">
<ul class="navigation" style="; border-radius: 10px; ">
<p style="display: inline" id="hp">
<a href="http://www.nytimes.com">Go Back To Home</a>
</p>
<li><a href="http://www.somelink.com">Women Fashin</a>
</li>
<li><a href="http://www.somelink.com">Men fashion</a>
</li>
</ul>
</div>
</div>
答案 1 :(得分:1)
您可以尝试这样:
<script>
$( document ).ready(function() {
$( "div.first a" ).hover(function() {
$( '#hp' ).fadeOut( 'slow');
});
});
</script>