• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

Changing current state on CSS tabs

Installed this menu... works perfectly.  

http://www.dynamicdrive.com/style/csslibrary/item/glossy_horizontal_menu/

Problem is, I'm not sure how to change the active tab (class="current") dynamically.  

I've tried the code below and it changes the active tab, but the 'menub_hover_left.gif' image seems to be layered underneath the 'menub_hover_right.gif' image.  It works fine on hover or if I manually change the class to .current.

Any help on how I can fix this?
The attached image shows HOME when I hover and SIGN UP as the active page body id="signup"
<-- Menu Code -->
<ul class="glossymenu">
	<li class="current"><a href="/"><b>Home</b></a></li>	
	<li id="t-signup"><a href="/SignUp"><b>Sign Up</b></a></li>	
	<li id="t-help"><a href="/Support"><b>Help</b></a></li>	
</ul>

<!-- Part of the CSS --->
.glossymenu li.current, .glossymenu li a:hover ,
body#home #t-home a,
body#signup #t-signup a,
body#help #t-help a

{
	color: #fff;
	background: url(../../Images/menu/menub_hover_left.gif) no-repeat left top; /*left tab image path*/
	background-position: left;
}

.glossymenu li.current a b, .glossymenu li a:hover b,
body#home #t-home a,
body#signup #t-signup a,
body#help #t-help a
{
	color: #fff;
	background: url(../../Images/menu/menub_hover_right.gif) no-repeat right top; /*right tab image path*/
}

Open in new window

menu.jpg
0
MFredin
Asked:
MFredin
  • 7
  • 5
  • 2
1 Solution
 
DesignbyonyxCommented:
The code you have posted is too incomplete to give advice on.  Can you please post a url, and we can help you fix this in a jiffy.

~Ryan
0
 
ZadoCommented:
Try this (javascript):
$(document).ready(function() {
	//On Click Event
	$("ul.glossymenu li").click(function() {
		$("ul.glossymenu li").removeClass("current"); //Remove any "current" class
		$(this).addClass("current"); //Add "current" class to selected tab
		return false;
	});
});

Open in new window

0
 
MFredinAuthor Commented:
Hey Ryan,

Here's the URL:  http://tinyurl.com/254je52
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZadoCommented:
My code corrected:

Place this in <head> section:
<script type="text/javascript">
$(document).ready(function() {
        //On Click Event
        $("ul.glossymenu li").click(function() {
                $("ul.glossymenu li").removeClass("current"); //Remove any "current" class
                $(this).addClass("current"); //Add "current" class to selected tab
                return false; //Try with this line or without
        });
});
</script>

Open in new window

0
 
MFredinAuthor Commented:
Thanks Zado,

I updated with your code.  For some reason, the links do not work now.  The state does hold on the correct tabs when click them though.  But I think a CSS based solution is best.  What if my users dont have javascript enabled for whatever reason?
0
 
ZadoCommented:
I can see it works (I used URL you provided), I think you need to use javascript, I don't think you can use css for this.
0
 
ZadoCommented:
Sorry, didn't look at source code, but menu buttons work properly. Also this might help:
http://www.sohtanaka.com/web-design/examples/tabs/
You can find more examples, search 'jquery tabs' in google.
0
 
MFredinAuthor Commented:
Thanks Zado.  When I use the javascript code you provided, the links do not actually work... the tab class changes but I can not navigate from page to page.  

Thank you for the link.  I've looked at jquery tabs and others but the solution I have just plain looks better in my opinion, that's why I want to use it over jquery tabs.
0
 
ZadoCommented:
I'm not sure you can do it without jquery, jquery tabs is the most popular way to do this.

Well, you can also create separate pages and mark proper tag with class=current in each page, but that's not what you want to do obviously.

However, I would recommend jquery tabs, but choice is yours.
0
 
MFredinAuthor Commented:
Is it possible to recreate this same look using jquery tabs?
0
 
DesignbyonyxCommented:
0
 
MFredinAuthor Commented:
I've used jqueryui tabs before... the problem is, they don't have the look of the tabs on my page.  I'm after the style mainly.
0
 
ZadoCommented:
Please grant the points and close the question, thanks :-)
0
 
ZadoCommented:
To be clear here: I'm not asking for grant the points to me, but generally.
If you have a problem with any suggestion from experts or nothing works with your expectation, please let us know, so we will continue work on solution for you, thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now