Solved

Changing current state on CSS tabs

Posted on 2010-11-29
14
438 Views
Last Modified: 2012-05-10
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
Comment
Question by:MFredin
  • 7
  • 5
  • 2
14 Comments
 
LVL 14

Expert Comment

by:Designbyonyx
Comment Utility
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
 
LVL 8

Expert Comment

by:Zado
Comment Utility
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
 

Author Comment

by:MFredin
Comment Utility
Hey Ryan,

Here's the URL:  http://tinyurl.com/254je52
0
 
LVL 8

Accepted Solution

by:
Zado earned 250 total points
Comment Utility
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
 

Author Comment

by:MFredin
Comment Utility
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
 
LVL 8

Expert Comment

by:Zado
Comment Utility
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
 
LVL 8

Expert Comment

by:Zado
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:MFredin
Comment Utility
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
 
LVL 8

Expert Comment

by:Zado
Comment Utility
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
 

Author Comment

by:MFredin
Comment Utility
Is it possible to recreate this same look using jquery tabs?
0
 
LVL 14

Expert Comment

by:Designbyonyx
Comment Utility
0
 

Author Comment

by:MFredin
Comment Utility
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
 
LVL 8

Expert Comment

by:Zado
Comment Utility
Please grant the points and close the question, thanks :-)
0
 
LVL 8

Expert Comment

by:Zado
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now