473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Current page condition

Is there a way to change the color of a link in a navbar if the address of
the link is the current page?
For instance if I have:

Home - index.php
Products - products.php
Contact - contact.php

Let's say I'm on the home page, and the Home link is dark green whereas
Products and Contact are green.
Now I go to the Products page and Home and Contact are green whereas
Products is dark green.
So far I have always used a class="current" attribute to diferenciate, but
maybe there is a more simple CSS way to do it. How would you do it?
Thanks,

--

Kerberos.

http://www.opera.com
http://www.freebsd.org
http://www.osresources.com
http://exodus.jabberstudio.org
Jul 21 '05 #1
10 2252
Kerberos wrote:
Is there a way to change the color of a link in a navbar if the address of
the link is the current page?


Not with CSS. JavaScript might be able to do it. Generally the best solution
is to generate your menu on the server (or before the code reaches the
server) and have that menu entry not be a link at all (recursive links are
not a great idea).

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 21 '05 #2
On Sat, 18 Dec 2004 20:26:32 -0200, Kerberos <me@privacy.net> wrote:
Is there a way to change the color of a link in a navbar if the address of
the link is the current page?


Yes, rewrite your page so that pages don't link to themselves. There's
never any need for it,

Steve

Jul 21 '05 #3
Steve Pugh <st***@pugh.net> wrote:
On Sat, 18 Dec 2004 20:26:32 -0200, Kerberos <me@privacy.net> wrote:
Is there a way to change the color of a link in a navbar if the address of
the link is the current page?


Yes, rewrite your page so that pages don't link to themselves. There's
never any need for it,


There *is* a need for it if you prefer to share a single template
among a number of pages instead of having to maintain separate,
nearly-but-not-quite-identical copies of your navigation bar on every
page.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 21 '05 #4
Kerberos <me@privacy.net> wrote:
Is there a way to change the color of a link in a navbar if the address of
the link is the current page?
For instance if I have:

Home - index.php
Products - products.php
Contact - contact.php

Let's say I'm on the home page, and the Home link is dark green whereas
Products and Contact are green.
Now I go to the Products page and Home and Contact are green whereas
Products is dark green.
So far I have always used a class="current" attribute to diferenciate, but
maybe there is a more simple CSS way to do it. How would you do it?


On the home page:

<body id="homepage">

On the products page:

<body id="productspage">

On the contact page:

<body id="contactpage">

On all pages:

<a class="navlink" id="navhome" href="index.php">...</a>
<a class="navlink" id="navproducts" href="products.php">...</a>
<a class="navlink" id="navcontact" href="contact.php">...</a>

In CSS:

a.navlink { color: #080; }
#homepage #navhome,
#productpage #navproduct,
#contactpage #navcontact { color: #030; }
--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 21 '05 #5
Harlan Messinger wrote:
Yes, rewrite your page so that pages don't link to themselves. There's
never any need for it,
There *is* a need for it if you prefer to share a single template
among a number of pages


Get a better template engine?

<ul>
[% FOR link IN menu %]
<li>
[% UNLESS link.href == current_url -%]
<a href="[% link.href %]">
[% END -%]
link.text
[% UNLESS link.href == current_url -%]
</a>
[% END -%]
</li>
</ul>

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 21 '05 #6
Harlan Messinger wrote:
Yes, rewrite your page so that pages don't link to themselves. There's
never any need for it,
There *is* a need for it if you prefer to share a single template
among a number of pages


Get a better template engine?

<ul>
[% FOR link IN menu %]
<li>
[% UNLESS link.href == current_url -%]
<a href="[% link.href %]">
[% END -%]
[% link.text %]
[% UNLESS link.href == current_url -%]
</a>
[% END -%]
</li>
</ul>

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 21 '05 #7
On Sat, 18 Dec 2004 21:30:03 -0500, Harlan Messinger
<hm*******************@comcast.net> wrote:
Steve Pugh <st***@pugh.net> wrote:
On Sat, 18 Dec 2004 20:26:32 -0200, Kerberos <me@privacy.net> wrote:
Is there a way to change the color of a link in a navbar if the address of
the link is the current page?


Yes, rewrite your page so that pages don't link to themselves. There's
never any need for it,


There *is* a need for it if you prefer to share a single template
among a number of pages instead of having to maintain separate,
nearly-but-not-quite-identical copies of your navigation bar on every
page.


Don't use plain SSI for your nav bar?
Use PHP, ASP, Cold Fusion, even X-SSI would let you remove the link
from the entry to the current page.

Ditto, if you're using some sort of desktop system such as a
pre-processor.

Steve

Jul 21 '05 #8
*David Dorward* <do*****@yahoo.com>:

[% FOR link IN menu %]
<li>
[% UNLESS link.href == current_url -%]
<a href="[% link.href %]">
[% END -%]
[% link.text %]
[% UNLESS link.href == current_url -%]
</a>
[% END -%]
That better look something like:

[% FOR link IN menu %]
<li><a
[% UNLESS link.href == current_url -%]
href="[% link.href %]"
[% END -%][% link.text %]</a>


Actually template-engines should not do scripting themselves, but maybe
this is the exception to the rule.

--
Ociffer, I swear to drunk, I'm not God!
Jul 21 '05 #9
David Dorward <do*****@yahoo.com> wrote:
Harlan Messinger wrote:
Yes, rewrite your page so that pages don't link to themselves. There's
never any need for it,

There *is* a need for it if you prefer to share a single template
among a number of pages


Get a better template engine?

<ul>
[% FOR link IN menu %]
<li>
[% UNLESS link.href == current_url -%]
<a href="[% link.href %]">
[% END -%]
[% link.text %]
[% UNLESS link.href == current_url -%]
</a>
[% END -%]
</li>
</ul>


Well, yeah, if your links are in a database.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 21 '05 #10
Harlan Messinger wrote:
Well, yeah, if your links are in a database.


So put them in a "database". It isn't difficult, it could be as simple
as a text file containing a link and link text per line:

/somepage/ | Page Title
/some/other/page | Other Page Title

etc

--
David Dorward

Jul 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: atabhcy | last post by:
Hello All, I have a python script which sends out email once a particular condition is met. Now I want to extend the functionality and make this script update a php web page with the same contents...
5
by: lucanos | last post by:
Hey Guys, Hoping that you can help me, as I have been scratching my head and getting nothing but dandruff... SITUATION --------- I have a webpage which users will be viewing, which has forms...
1
by: Tony | last post by:
I have a form in access that has 5 fields for a certain record: 1)Date mailed, 2)Date received, 3)Date completed 4)Foreign Content amount and 5)record number. If the foreign content (FC)is >15% of...
2
by: Tony | last post by:
Hello, I am having difficulty in getting the current record of the current form to show after pressing a command button that takes me to another form. The command button takes me to another...
2
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: cyberteck | last post by:
hi all, I have a page which i have two condition on this page. if it follows the first condition then it simply open the popup page and do something and it get closed. but in case of second...
2
by: sindhu | last post by:
Hello, I'm loading a frame from another frame using anchor tag. the code is as folllows. function change_page { if(document.form.txtbx1.value=="all") { ...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.