473,804 Members | 3,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2278
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="productspag e">

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.p hp">...</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

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

Similar topics

4
1443
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 as those of the emails it sends out. What module /commands can help me acheive this? Thanks.
5
2533
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 which can be hidden or displayed at the user's choice. The problem is that they want the page to refresh every X seconds, but if it refreshes when a
1
8820
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 the invoice amount (inv amt.on another form) then I want a my report to run automatically for the record I am on in the current EC Input form when I enter in the foreign content amount. I have a query built for the report. Currently, when the...
2
5322
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 form that I want to show the record of the previous form I left. The problem is that the form does not show any other record but the current one from the previous form. I want it to open to that current record and it does however I can only view...
2
3053
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 content based on the user's role. I wrote this to do it: if (HttpContext.Current.User.Identity.IsAuthenticated) { plLoggedIn.Visible = true;
6
11305
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" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
1
1558
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 condition control has to go for some page suppose login page and after getting login successfull it has to open same popup page that was opened in first condition. actually on login page i send the header location to required url. like this------- ...
2
2499
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") { document.getElementById('a_link').target="right_bottom";
3
8913
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 used Cache and Session objects, and currently I assume HttpContext.Current object to be existent. Also, since I do not have this check, some of my unit test cases fail because there is no HttpContext for them.
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.