因此,我正在編寫一個菜單,並希望它基於該頁面保持某種顏色。 我在頁面上添加了「class ='active'」,我嘗試將它添加到CSS,但它不起作用。有任何想法嗎?如何使用php + css更改活動菜單的樣式
PHP代碼:
<?php
$currentPage = basename($_SERVER['REQUEST_URI']);
print "<div id = 'submenu-container'>";
print "<div id = 'submenu'>";
print "<ul class = 'about'>";
print " <li><a href='about.php#about_intro.php'if($currentPage=='about.php#about_intro.php' || $currentPage=='about.php') echo 'class='active''>About</a></li>";
print " <li><a href='about.php#about_team.php'if($currentPage=='about.php#about_team.php') echo 'class='active''>Team</a></li>";
print " <li><a href='about.php#about_services.php' if($currentPage=='about.php#about_services.php') echo 'class='active'>Services</a></li>";
print " </ul>";
print "</div>";
print"</div>";
?>
CSS:
#submenu ul li a .active {
background:#FFF;
}
我將如何添加與JavaScript的活動類?對不起,我對JS沒有那種經驗,我一直選擇它,從未正式自學過。 – Andrew