Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing current state on CSS tabs

Posted on 2010-11-29
14
Medium Priority
?
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
LVL 8

Accepted Solution

by:
Zado earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

636 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