Refael
asked on
CSS hover state with php include
Hi experts,
I am just doing a simple website in PHP where the top menu is based on CSS and its being included to every page with <?php include "top-menu.php"; ?>
I want the top menu CSS will show the hover state in its link. For example if one of the menu links is "about us" and the user view the "about us" page then the menu will show the links hover state in the menu.
I know of course how to do it in CSS but I do not know how to "tell" the menu to hover on a link according to the viewed page.
Can somebody direct me?
I am just doing a simple website in PHP where the top menu is based on CSS and its being included to every page with <?php include "top-menu.php"; ?>
I want the top menu CSS will show the hover state in its link. For example if one of the menu links is "about us" and the user view the "about us" page then the menu will show the links hover state in the menu.
I know of course how to do it in CSS but I do not know how to "tell" the menu to hover on a link according to the viewed page.
Can somebody direct me?
ASKER
Hi glcummins
can you please and kindly show me a full exmaple.. just for one page as i am php pioneer :-) .... what does this means "link the $currentPage identifier to the current menu item"?
can you please and kindly show me a full exmaple.. just for one page as i am php pioneer :-) .... what does this means "link the $currentPage identifier to the current menu item"?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hey great! i do not use UL and LI but i got the concpet ... very neat!
thanks a lot!
thanks a lot!
In each script, create a variable to hold an identifier for the current page:
<?php
$currentPage = "about us";
?>
Then, in the 'top-menu.php' page, as you cycle through the menu items, check if $currentPage matches the current menu item:
<?php
if ($currentPage == $currentMenuItem)
{
echo " class=active";
}
?>
You will need create a class that will differentiate the look of the 'active' menu item from the others, and you will also need to find a common way to link the $currentPage identifier to the current menu item.