如何突出显示网站菜单上的活动选项卡

How to highlight active tab on the website menu?

本文关键字:活动 选项 菜单 何突出 显示 网站      更新时间:2023-09-26

我的问题是:我有一个菜单项,我想突出显示用户切换到的活动选项卡,它肯定指向另一个页面

堆叠流用途:

.nav {
    float: left;
    font-size: 125%;
}
.nav ul {
    margin: 0;
}
.nav li {
    background: none repeat scroll 0 0 #777777;
    display: block;
    float: left;
    margin-right: 7px;
}
**.nav .youarehere {
    background: none repeat scroll 0 0 #FF9900;
}**
.youarehere a {
    color: #FFFFFF;
}
.nav li:hover {
    background-color: #FF9900;
}
.nav a {
    color: #FFFFFF;
    display: block;
    padding: 6px 12px;
    text-decoration: none;
}

有人能告诉我他们还用什么做这件事吗?

使用我以前在页面上使用过的Javascript的一种方法是

将所有侧边栏按钮放在一个名为sideBarButton的CSS类中。activeSideBarButton将是当链接与当前窗口的位置相同时设置的类。

$(document).ready(function () {
    var sideBarButtons = $(".sideBarButton");
    for(var i in sideBarButtons)
    {   
      if(!sideBarButtons[i].pathname)
      {   
        continue;
      }   
      if(sideBarButtons[i].pathname == window.location.pathname)
      {   
        sideBarButtons[i].className += ' activeSideBarButton';
        console.log("Enabled button " + sideBarButtons[i]);
      }   
    } 
});