I want to implement my navigation tabs somewhat like the ones on this site, and I’ve heard that this was built using ASP.Net MVC. If I’m on stackoverflow.com/users, than the “Users” menu tab is orange and all others stay grey, same if a different tab is selected.
I am pretty good with manipulating the css to change color when it’s hovered or selected, etc, and adding/removing/authorizing items in the menu container, but not familiar with how to change the color of the tab based on the tab page that I’m on. Any quick and dirty way to accomplish this?
Assign a unique id to the body element of each page (e.g.
<body id="users">). In ASP.NET MVC you could have the body tag in your master page written like:<body id="<%= ViewData["bodyId"] %>">And in the Controller methods for each page put something like
ViewData["bodyId"] = "users";to dynamically assign the id for each page.Then in your nav markup, assign a class with the same name on the <a> tag that links to that page:
Then in the css do something like this:
That will assign your “current page” styles to any link tag with a class that matches the body tag id.