我的问题是:
我有一个菜单项,我想突出显示用户切换到的活动标签,确保指向另一个页面
stackover flow使用:
.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;
}
有人可以告诉我他们还有什么用来做这项工作吗?
答案 0 :(得分:2)
使用之前在我的网页上使用过的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]);
}
}
});