Solved

Changing current state on CSS tabs

Posted on 2010-11-29
14
441 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
ID: 34235200
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
ID: 34235227
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
ID: 34235314
Hey Ryan,

Here's the URL:  http://tinyurl.com/254je52
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 8

Accepted Solution

by:
Zado earned 250 total points
ID: 34235366
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
ID: 34235407
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
ID: 34235418
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
ID: 34235462
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
 

Author Comment

by:MFredin
ID: 34235499
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
ID: 34235526
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
ID: 34235607
Is it possible to recreate this same look using jquery tabs?
0
 
LVL 14

Expert Comment

by:Designbyonyx
ID: 34235979
0
 

Author Comment

by:MFredin
ID: 34236091
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
ID: 34317468
Please grant the points and close the question, thanks :-)
0
 
LVL 8

Expert Comment

by:Zado
ID: 34384846
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

785 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