Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
Here's a simple example of how I do this (sometimes I also do it in JavaScript, also, which is super-simple, since you can match the window location against the href of the link):
Let's say this is index.php:
PHP Code:
<?php page="index";?> <html> <head> <title>Home</title> <!--meta, etc.--> <?php include "header.php";?> <!--document continues here-->
Now, let's say this is header.php:
PHP Code:
<link href="master.css" rel="stylesheet" type="text/css" /> <!--Links to scripts, etc--> </head>
<body class="<?php echo $page?>"><!--note class on body is the same as the page name. This is handled from an included file so that this code doesn't have to be repeated constantly. This is nice because it gives us the opportunity to easily identify each page in the CSS document-->
<div id="wrapper"><!--each <li> has a unique id that matches the page name--> <ul id="navigation"> <li id="index"><a href="/">Home</a></li> <li id="about"><a href="/about.php">About</a></li> <li id="contact"><a href="/contact.php">Contact</a></li> </ul>
Now, let's say this is the CSS file that we have linked to, called master.css:
CSS
Code:
.index #index a, .about #about a, .contact #contact a {
background: #fff !important; /*or whatever you need as an active style. This is tagged with !important so that it covers the :visited state, but if you wish to have seperate styles for :visited links, you will need to specify this and drop the !important*/
}
__________________
I build web things. I work for the startup Please login or register to view this content. Registration is FREE
.
Last edited by wayfarer07; 09-10-2008 at 11:10 AM..
|