Forum Moderators: not2easy

Message Too Old, No Replies

Menu current Page prob

How can I make the current menu item same as :active

         

Chuckmek

1:30 am on Jan 17, 2005 (gmt 0)

10+ Year Member



Is there any way to make a manue item that is clicked hold its :active formatting. As soon as it goes to the new page, it goes bak to teh a.menu formatting.. Any way around this?

This is what I curerntly have:

CSS
----
a.menu:link, a.menu:visited {display:block; width:93px; height:28px; background:#FFC724;border-Right:1px solid #FFFFFF;border-Bottom:1px solid #FFFFFF; color:#FFFFFF; text-decoration:none; text-align:center; line-height:25px; font-family: Arial, Helvetica, sans-serif; font-weight:bold; font-size:11px; float:left;

a.menu:hover {background:#0099FF; color:#FFFFFF;}
a.menu:active {background:#2665DA; color:#FFFFFF;}

And this is my HTML
------------
<td colspan="2" align="center">
<div id="menua">
<a class="menu" href="default.asp">Home</a>
<a class="menu" href="programs.asp">Programs</a>
<a class="menu" href="lilbro.asp">Little Brothers</a>
<a class="menu" href="activities.asp">Activities</a>
<a class="menu" href="fundraising.asp">Fundraising</a>
<a class="menu" href="donate.asp">Donate</a>
<a class="menu" href="newsletter.asp">Newsletter</a>
<a class="menu" href="about.asp">About Us</a>
</div>
<div class="clr"></div>
</td>

Any help would be appreciated...thanks..

createErrorMsg

2:42 am on Jan 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are numerous ways to style a "current page" link. Some involve scripting (it can be done with JS or PHP) used in combination with CSS. These solutions are extremely powerful as they allow you to update your navigation and have the "current" effect automatically apply to any new items.

Some prefer not to use scripting alternatives. In this case, there is a pure CSS solution, but it requires a small amount of manual updating if the nav menu changes.

This last solution was dicussed in this recent thread [webmasterworld.com].

And by the way, welcome to WebmasterWorld!

cEM

alias

11:36 am on Jan 17, 2005 (gmt 0)

10+ Year Member



This is what I've been doing in such cases. But this sample requires php.

<a href="?i=1" class="<?=($i=="1"? 'active' : 'menu')?>">news</a>
<a href="?i=2" class="<?=($i=="2"? 'active' : 'menu')?>">about</a>

Here you can see: when the variable passed to the 'i' is equal to 1 - the style is set to active, in other case it's just menu. If you do not pass any variables, you could probably use the referring page value from the system variables.

Chuckmek

6:18 pm on Jan 17, 2005 (gmt 0)

10+ Year Member



Thanks createErrorMsg!

That worked great.

I just added:
CSS:
#page_one #one{background:#2665DA; color:#FFFFFF;}
#page_two #two{background:#2665DA; color:#FFFFFF;}
#page_three #three{background:#2665DA; color:#FFFFFF;}
#page_four #four{background:#2665DA; color:#FFFFFF;}
#page_five #five{background:#2665DA; color:#FFFFFF;}
#page_six #six{background:#2665DA; color:#FFFFFF;}
#page_seven #seven{background:#2665DA; color:#FFFFFF;}
#page_eight #eight{background:#2665DA; color:#FFFFFF;}

HTML (the header file only):
<div id="menua">
<a class="menu" id="one" href="default.asp">Home</a>
<a class="menu" id="two" href="programs.asp" id="current">Programs</a>
<a class="menu" id="three" href="lilbro.asp">Little Brothers</a>
<a class="menu" id="four" href="activities.asp">Activities</a>
<a class="menu" id="five" href="fundraising.asp">Fundraising</a>
<a class="menu" id="six" href="donate.asp">Donate</a>
<a class="menu" id="seven" href="newsletter.asp">Newsletter</a>
<a class="menu" id="eight" href="about.asp">About Us</a>
</div>

And the Body Tag of Each page:
<body id="page_eight"> or whatever page it is supposed to be! Awesom...Thanks so much!

createErrorMsg

8:39 pm on Jan 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chuck, glad to hear it worked for you.

I just added:
CSS:
#page_one #one{background:#2665DA; color:#FFFFFF;}
#page_two #two{background:#2665DA; color:#FFFFFF;}
#page_three #three{background:#2665DA; color:#FFFFFF;}
#page_four #four{background:#2665DA; color:#FFFFFF;}
#page_five #five{background:#2665DA; color:#FFFFFF;}
#page_six #six{background:#2665DA; color:#FFFFFF;}
#page_seven #seven{background:#2665DA; color:#FFFFFF;}
#page_eight #eight{background:#2665DA; color:#FFFFFF;}

If you're interested in saving code space, you can combine all these seperate rule declarations into one (since the property/value pairs are the same for all of them). It's not much, but it will cut down a little on the CSS size and, for future applications, cuts down on the amount of code you have to type...

#page_one #one,
#page_two #two,
#page_three #three,
#page_four #four,
#page_five #five,
#page_six #six,
#page_seven #seven,
#page_eight #eight {
background:#2665DA;
color:#FFF;
}

This applies the style rules to all of the selectors in the comma seperated list. The newlines are not necessary, but make it a little easier for humans to read.

cEM

Chuckmek

9:05 pm on Jan 17, 2005 (gmt 0)

10+ Year Member



Great...will do..CSS is way better than what this was done with before....thanks again.