How to change css for active link based on the hashtag

前端 未结 2 667
轻奢々
轻奢々 2021-01-22 02:37

I have a situation here on how to change my active link css based on the hashtag. All the content was in the same page and I use the #url section to call the content.

i

2条回答
  •  执念已碎
    2021-01-22 03:38

    What I can suggest is using jQuery. Somthing like this.

    $(document).ready(function(){
    $('div#services_menu li').click(
        function(e)
        {
            $('div#services_menu li').removeClass('active');
            $(e.currentTarget).addClass('active');
        }
    );
    });
    
    
    li.active a
    {
        color: #BBA842!important;
    }
    

    Because, first of all you are using anchor links, and you want to make it dynamic. If any other person can suggest solution using CSS I will appreciate that answer.

提交回复
热议问题