CSS 技巧是
#menu a:active {
color: #f00;
}
:hover 和 :visited
相同
祝你好运!
编辑
既然您希望指向您所在页面的链接样式不同,我需要更多详细信息。你使用 PHP 吗?你不是每页使用一个 php 脚本吗?
无论如何,如果您有一个包含在所有页面中的 header.php 文件,或者您只是懒得对每个链接的类进行硬编码,这应该可以工作。
PHP:
// Return $return if this page is $page, false otherwise
function is_current($page, $return) {
$this_page = $_SERVER['SCRIPT_NAME']; // will return /path/to/file.php
$bits = explode('/',$this_page);
$this_page = $bits[count($bits)-1]; // will return file.php, with parameters if case, like file.php?id=2
$bits = explode('?',$this_page);
$this_script = $bits[0]; // will return file.php, no parameters
return ($page == $this_script?$return:false); // return $return if this is $page, false otherwise
}
CSS
/* blue, no underline when normal */
a {
text-decoration: none;
color: #00f;
}
/* red, underlined when class active */
a.active {
text-decoration: underline;
color: #f00;
}
你的文件
<!-- Simply echo the function result for each link class -->
<a href="home.php" class="<?php echo is_current('home.php','active'); ?>">Home</a>
<a href="about.php" class="<?php echo is_current('about.php','active'); ?>">About</a>