Navbar highlight for current page

前端 未结 3 1011
野趣味
野趣味 2021-02-04 12:58

I was wondering how I would add the ability to add a highlight box the nav bar on the page your currently on. You know so people know what page their on.

Very much like

3条回答
  •  清歌不尽
    2021-02-04 13:14

    You can use the jquery function window.location.href to compare the site you are on right now with your href of < a > in the list element. For example, "index.html":

  • Home
  • The code below searches for the href of the active page in the list elements < a >. Then adds the class "active" with addClass('active') to the active pages < a > so that you can now call it via CSS. Put this code in the head of your html file.

    
    
    

    You can now add your css conditions like changing the color:

    #nav_bar .active {
        color:            #F8F8F8;
        background-color: #4f81bd;
    }
    

提交回复
热议问题