javascript - Keep active menu item highlighted - Stack Overflow

How would I make it so that the item that is clicked in the menu, stays highlighted blue. So basically

How would I make it so that the item that is clicked in the menu, stays highlighted blue. So basically the active menu item.

Fiddle

I've tried using css active, but im thinking I need javascript or something.

 #cssmenu > ul li > a:active, #cssmenu > ul li:active > a {
    color: #ffffff;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    background: #54cdf1;
    background: -webkit-linear-gradient(#72d4f2, #54cdf1);
    background: -moz-linear-gradient(#72d4f2, #54cdf1);
    background: linear-gradient(#72d4f2, #54cdf1);
    border-color: transparent;
}

How would I make it so that the item that is clicked in the menu, stays highlighted blue. So basically the active menu item.

Fiddle

I've tried using css active, but im thinking I need javascript or something.

 #cssmenu > ul li > a:active, #cssmenu > ul li:active > a {
    color: #ffffff;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    background: #54cdf1;
    background: -webkit-linear-gradient(#72d4f2, #54cdf1);
    background: -moz-linear-gradient(#72d4f2, #54cdf1);
    background: linear-gradient(#72d4f2, #54cdf1);
    border-color: transparent;
}
Share asked Oct 3, 2013 at 18:47 user1938745user1938745 1932 gold badges5 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You'll need some JS for that.

$(document).ready(function() {
    $("#cssmenu li").on("click", function() {
        $("#cssmenu li").removeClass("active");
        $(this).addClass("active");
    });
});

Then just style #cssmenu li.active the way you want it in your CSS.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742406507a4437956.html

相关推荐

  • javascript - Keep active menu item highlighted - Stack Overflow

    How would I make it so that the item that is clicked in the menu, stays highlighted blue. So basically

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信