Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tabbed Navigation Bar

Status
Not open for further replies.

NeedFood

MIS
Dec 15, 2004
3
US
I'm trying to create a tabbed navigation bar using <div><ul><li>. I can change the font color and background-color when the tab menu is hover, active, or visited.

How can I change the background-color of the tab menu you just clicked? Yahoo website tabbed navigation bar is an example < My navigation bar doesn't have to be that fancy. I just want to change the font color and background-color when you click on the tab menu. (and the color has to stay until you click on a different tab.)

Please give me advice. Thank you.
 
Use javascript: forum216

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
For normal links and hovers it is not a problem. You can do that with css pseudo classes :)link, :hover). :active should solve the third option but it is not properly implemented in any of the browsers. You will have to use another class to describe the 'selected' option. If you have static pages that will be simple, simply add <a href="..." class="active"> to your selected link and describe the active background and color in your css. For dynamic pages you will have to build a mechanism that will check which option is currently selected.
 
To be able to save the last clicked box, you will need some modicum of Javascript unless the tab navigates to a new page when you mouse over. In that case, you wouldn't be able to save it anyway.

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
If he has a static page, let's say three pages: home.html, aboutme.html and contact.html, he can have 3 buttons and apply .active class to the button that the page represents. No JS needed, the effect is what he was looking and it works. In a dynamic page, he would have to determine which page it is (read the file, read the variable that defines the page...) and then apply .active class to that link. No JS neccessary again.
 
Yes, if they are in multiple pages. Are they?
If the buttons are on the same page or in a frame, then Javascript is necessary.

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
To expand upon what Vragabond has said. I used the following technique on my own site. My navigation is in an included file (for ease of editing) so this worked well for me...

Look at
Each item in the navigation has a class associated with it.

At the top of each page, the class for the navigation item is changed to reflect which page you are on.

This works because of the cascading nature of stylesheets.
[ol]
[li]External styles are applied first.[/li]
[li]Then Internal stylesheets.[/li]
[li]And finally inline styles.[/li]
[/ol]
So you can effectively over-ride any already defined styles.


NOTE: Looking at what I did, perhaps ID's would be more suitable than classes.

- Web design and ranting
- Day of Defeat gaming community
"I'm making time
 
Thank you all for replying to my question. I appreciate it. I'm trying to make my tabbed navigation bar on a User Control (ASP.NET). So, since the navigation is not static, I'll use JavaScript.
 
Just bear in mind that if the user has Javascript disabled then the effect will not work.

In what way is the navigation not static? You mean the items in it change depending on what page the user is on?

If so, then why not do as Vragabond suggested and create a ".active" class. Then dynamically assign that class to the corresponding nav element using a conditional.

- Web design and ranting
- Day of Defeat gaming community
"I'm making time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top