CSS Active Links

This is a discussion on "CSS Active Links" within the Web Page Design section. This forum, and the thread "CSS Active Links are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 11th, 2006, 17:02
Junior Member
Join Date: Aug 2006
Location: Manchester
Age: 26
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
CSS Active Links

Hi guys,

I want to create a menu that is going to be called from an include file.

The problem is i want the link to appear differently when you are on that page. So for example if you are on the home page the homepage button will be blue and the rest of the buttons will be grey.

Is it possible in CSS to set an active link to a different colour? (i have tried the a:active but thats just for mousedown isnt it?)

I would also like the current link to be inactive so you cant select it - is this also possible?

thanks
john
Reply With Quote

  #2 (permalink)  
Old Aug 11th, 2006, 17:13
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,713
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Active Links

Not sure how this would work with an include but.

Set an id or class for it.

#foo li#current a {} etc...

<li id="current"><a href="" title="">Foo!</a></li>
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Aug 11th, 2006 at 20:08.
Reply With Quote
  #3 (permalink)  
Old Aug 11th, 2006, 22:06
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: CSS Active Links

How is your JavaScript coding? I do what you want to do on my web sites but rather than just drop the answer in your lap, so to speak, I'll give you some pointers. That way you learn more.

Give each of your links a unique id.

Create a css style to be used with the inactive link.

Use a meta tag to give each page an identifier.

Write some JavaScript that runs 'onload' which searches your navigation for a link id that fits with the page identifier. Then use JavaScript to replace the a link with a span and asign the css style for the inactive link.
Reply With Quote
  #4 (permalink)  
Old Aug 11th, 2006, 22:26
Junior Member
Join Date: Aug 2006
Location: Manchester
Age: 26
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Active Links

Hi Geoff, my JavaScript knowledge is ok, not very good at writing from scratch but I can modify code to get it to do what i want... usually ;-)

I have actually found some code now on a forum and modified it to suit what i wanted...ish:

Code: Select all
 
var links = new Array (
"rapport",
"flirt",
"hr"
);
 
var links_text = new Array (
"Rapport Unlimited",
"Flirt Guru",
"IBM HR campaign"
);
var links_url = new Array (
"portfolio_rapport.asp",
"portfolio_flirt.asp",
"portfolio_ibm_hr.asp"
);
var loc=String(this.location);
loc=loc.split("/");
loc=loc[loc.length-1].split(".");
loc=loc[loc.length-2];
function percentinspiration_menu_gen()
{
for(var i=0; i<links.length; i++)
{
if(((this.location=="http://www.2percentinspiration.com") || (this.location=="http://www.2percentinspiration.com/") || (this.location=="http://2percentinspiration.com") || (this.location=="http://2percentinspiration.com/")) && (i==0))
{
document.write('<a href="' + links_url[i] + '" class="leftnav">' + links_text[i] + '</a>');
}
else
{
if(loc==links[i])
{
document.write('<span class="active">' + links_text[i] + '</span>');
}
else
{
document.write('<a href="' + links_url[i] + '" class="leftnav">' + links_text[i] + '</a>');
}
}
document.write(' ');
}
} 
percentinspiration_menu_gen();
The problem now is that because i have sub-pages within my nav the links wont stay highlighted.

Here is a link so you can see what i mean

http://www.2percentinspiration.com/R...io_rapport.asp

What i want is for the nav to stay highlighted even if your on one of the sub pages (e.g -2.asp or -3.asp)

OR (Ideally)

For the content to change within the same document rather than going to different pages - but have no idea how to achieve this

Hope this makes sense?

thanks
J
Reply With Quote
  #5 (permalink)  
Old Aug 12th, 2006, 05:16
Reputable Member
Join Date: Jul 2005
Posts: 400
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Active Links

This is beyond simple... way over thinking it here.

As been said, have a unique id for each link.

On the page itself, add a style for the specific ID of that page link to make it appear how you want. There is nothing wrong with having specific styles defined within a page.

Code: Select all
 
<ul>
 <li id="foo1"><a href="" title="">Foo1</a></li>
 <li id="foo2"><a href="" title="">Foo2</a></li>
</ul>
 
On the html page itself....
 
foo1 page
 
<style>
#foo1 a:visited { attributes }
</style>
 
foo2 page
 
<style>
#foo2 a:visited { attributes }
</style>
Reply With Quote
  #6 (permalink)  
Old Aug 14th, 2006, 12:48
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,713
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Active Links

Yeah giving each link an id would be the simplest way
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
Reply

Tags
css, active, links

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
active active X R8515198 Flash & Multimedia Forum 11 May 18th, 2007 02:50
How do I get people active and keep them active? TheSealPortalTeam Webforumz Cafe 4 May 9th, 2007 10:17
Active State Lchad Web Page Design 10 Jan 27th, 2007 01:29
CSS - a:active ruffy Web Page Design 3 Nov 2nd, 2006 08:50
active x problem dbarrie Web Page Design 3 Jul 19th, 2006 16:32


All times are GMT. The time now is 05:39.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43