的CSS技巧是
#menu a:active {
color: #f00;
}
同为:悬停和:参观
好运!
编辑
,现在你希望链接你在被风格化不同的页面看,我需要更多的细节。你使用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>
由于某种原因,这是行不通的。 – vla 2010-10-09 08:35:11
更新了上面的代码 – Claudiu 2010-10-09 09:34:23