I'm new to this so I need your help, I have a navigation menu in my header. When a page is active, its tab has a special id named menu_active. I'm including this header.php in my pages to reduce redundancy.
This is what I've tried so far:
<nav>
<ul id="menu">
<?php
$pages = array( 'index.php' => 'Home', 'services.php' => 'Services', 'sitemap.php' => 'Calculators', 'about.php' => 'About'
, 'contact.php' => 'Contact' );
foreach( $pages as $url => $title ) {
$li = '<li ';
if( $url == 'index.php' ) {
$li .= 'class="alpha"';
} else if ( $url == 'contact.php' ){
$li .= 'class="omega"';
}
if( $_SERVER[ 'PHP_SELF' ] == $url ) {
$li .= 'id="menu_active"';
}
$li .= '><a href="' . $url . '"><span><span>' . $title . '</span></span></a></li>';
echo $li;
}
?>
</ul>
</nav>
UPDATE: *CSS*
#menu {
width:100%;
overflow:hidden;
margin-top:3px
}
#menu li {
float:left
}
#menu a {
display:block;
font-size: 18px;
font-weight:400;
color:#000;
background:url(../images/menu.gif) top repeat-x;
line-height:55px;
text-decoration:none;
}
#menu li span {
display:block;
background:url(../images/menu_left.gif) top left no-repeat
}
#menu .alpha span {
background:url(../images/left_menu.gif) top left no-repeat
}
#menu .alpha a:hover span, #menu .alpha#menu_active a span {
background:url(../images/left_menu_active.gif) top left no-repeat
}
#menu .omega span span {
background:url(../images/right_menu.gif) top right no-repeat
}
#menu .omega a:hover span span, #menu .omega#menu_active a span span {
background:url(../images/right_menu_active.gif) top right no-repeat
}
#menu li span span, #menu .alpha span span {
background:url(../images/menu_right.gif) top right no-repeat;
padding:0 60px
}
#menu a:hover, #menu #menu_active a {
color:#fff;
background:url(../images/menu_active.gif) top repeat-x
}
#menu a:hover span, #menu #menu_active a span {
background:url(../images/menu_left_active.gif) top left no-repeat
}
#menu a:hover span span, #menu #menu_active a span span, #menu .alpha#menu_active a span span, #menu .alpha a:hover span span {
background:url(../images/menu_right_active.gif) top right no-repeat
}
I can get to work the first and last menu, but the active states still to no avail. What seems to be the problem in here? And can you help what is the best practice to do this?