On this site, you may notice that when you use one of the links in the sliding navigation, that pages link stays highlighted.
I am going to teach you how to do this easily using CSS and PHP.
First, you are going to need to know if you can use PHP. This can be tested easily, just make a new file and call it test.php, and paste ONLY this into it:
Then go to that page, and if you see "You can use PHP!", then you are good to go and can read on. If you don't see that, then get a better host and come back later.
Ok, onto the good stuff. First, create a simple navigation. I usually use lists. This is just basic some HTML
Now, instead of putting the navigation on every single page, create a new file and call it something like "navigation.php", or whatever you prefer.
Now for the PHP code.
Adding a if() check to each navigation item, that will check what page the user is on. If the user is on a page, it will add the class "current" to the item, applying the appropriate style. Here is an example:
-
<ul id="navigation_example">
-
<li class="navigation-link <?php if($page == "home") {echo "current"; } ?>"><a href="index.php">Home</a></li>
-
<li class="navigation-link <?php if($page == "about") {echo "current"; } ?>"><a href="about.php">About</a></li>
-
<li class="navigation-link <?php if($page == "portfolio") {echo "current"; } ?>"><a href="portfolio.php">Portfolio</a></li>
-
<li class="navigation-link <?php if($page == "contact") {echo "current"; } ?>"><a href="contact.php">Contact</a></li>
-
</ul>
And now, for the final piece of PHP, add this to the top of every page:
-
<?php $page = "page_name"; ?>
Of course, replace "page_name" with the name of the current page that you used in the navigation menu. Then, include the navigation on the pages as well, like this:
-
<?php include('navigation.php'); ?>
That will place the navigation wherever you want it.
Now, finally the CSS. In this example, we'll make it a very simple vertical menu.
First, remove the bullets, some borders, and add a background color. While we're at it, add a hover to the links as well.
-
#navigation_example {
-
width: 150px;
-
list-style-type: none;
-
border: 2px solid black;
-
border-top: 0px;
-
margin: 0px;
-
padding: 0px;
-
}
-
-
#navigation_example .navigation-link {
-
width: 150px;
-
margin: 0px;
-
padding: 0px;
-
border-top: 2px solid black;
-
background: #c0c0c0;
-
}
-
-
#navigation_example .navigation-link a {
-
display: block;
-
margin: 0px;
-
padding: 5px;
-
background: #c0c0c0;
-
color: black;
-
font-weight: 900;
-
text-decoration: none;
-
}
-
-
#navigation_example .navigation-link a:hover {
-
background: #000000;
-
color: white;
-
}
That give you this:
Lastly, add a background color for the current item and you are done... Like so:
-
.current a {
-
background: #DAA520;
-
}
And the final product
The home security systems offering a lot of variety in different price packages are on the doorstep of low income housing group. The flooring and furniture remains an interesting feature for interior designers presenting diverse colors and shapes. These days the kids bedding has attracted attention of the interior experts. The carpet industry provides many solutions to their clients in terms of materials designs and colors. The developers giving a room to swimming pools dealers to transact their business with their customer's directly.




