如何保持活动链接的颜色恒定,直到我按下其他链接 [英] how to Keep the color of active link constant, until i press other link
本文介绍了如何保持活动链接的颜色恒定,直到我按下其他链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击一个链接时,它的颜色应该改变,并且在我按下另一个链接之前应该保持不变,该如何使用活动"呢?我尝试过,当我单击它时颜色会改变,但是它会恢复其原始颜色!
When i click on a link, its color should change, and it should be same until i press other link, How to do using "active"?? I tried, Its color changes when i click on it, But it gains its original color!
<html>
<head>
<style>
a
{
display:block;
height:5%;
width:10%;
background-color:#96C;
border: solid #96C 1px;
margin-top:5px;
}
a:hover
{
background-color:#666;
}
a:active
{
background-color:#C99;
}
</style>
</head>
<body>
<a href="#">Home</a>
<a href="#">Sign in</a>
<a href="#">Sign up</a>
<a href="#">Exit</a>
</body>
</html>
推荐答案
这不是:active伪类的本意.您可以为此使用javascript.如果您使用jQuery,则可以执行以下操作:
That's not what :active pseudo class was meant to do. You can use javascript for this. If you use jQuery, than you can do something like:
var items = $("a");
items.on("click",function(){
items.removeClass("active");
$(this).toggleClass("active");
});
并添加活动的" css规则
and add "active" css rule
a.active {
background-color:#C99;
}
请参见小提琴 http://jsfiddle.net/QQb27/
这篇关于如何保持活动链接的颜色恒定,直到我按下其他链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文