简体   繁体   English

在第一个链接悬停时更改其他链接的背景

[英]Changing the background of other link on hover of the First link

I have the following mark up. 我有以下标记。

<ul>
<li><a><span>link-1</span></a></li>
<li><a><span>link-2</span></a></li>
<li><a><span>link-3</span></a></li>
</ul>

When user hover on the first 'a' then the next a tag in LI , we remove the backgorund-image. 当用户将鼠标悬停在LI中的第一个'a'以及下一个标记上时,我们将删除backgorund-image。

I hope you are clear what I want to do with this. 希望您清楚我要怎么做。

You don't need JavaScript - hurray for CSS skills! 您不需要JavaScript-赶快来学习CSS技能吧!

You can do it with the adjacent selector ( + CSS selector), try hovering on a link in your HTML while using this CSS: 您可以使用相邻的选择器+ CSS选择器)来实现,尝试在使用此CSS时将鼠标悬停在HTML中的链接上:

ul li a {
    color: red
}
ul li:hover+li a {
    color: blue
}

( JSFiddle is a good testing ground.) JSFiddle是一个很好的测试场。)

Why you'd want something with such a low usability is beyond my comprehension. 为什么您想要具有如此低的可用性的东西超出了我的理解范围。
But perhaps it makes sence, in your scenario. 但是,在您的情况下,它可能具有意义。

使用Jquery.mouseout()删除背景。

I think you can do something like this 我想你可以做这样的事情

$('#linka').mouseover(function() {
     $(this).attr('class','somethingrandom'); //so that you can change remaining with ease
     $('.remaininga').removeclass('yourclass'); //whether add a new or remove
}).mouseout(function() {
     $(this).attr('class','remaininga');  //to bring back to previous state
});

What you actually need to do from my point, is change the class name each time so that you can change the class of remaining 从我的角度来看,实际上您需要做的是每次更改类名,以便您可以更改剩余的类。

You can use the jquery selectors 您可以使用jquery选择器

example

$('ul:eq(0) > li').css('background','none') $('ul:eq(0)> li')。css('background','none')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM