我试图让这个脚本工作,但不幸的是无事可做......我也认为有更好的方法来做到这一点,但不知道哪个?
所以我希望在打开的页面上按钮保持悬停状态,所以我创建了一个看起来像按钮悬停的类,并说如果当前页面名称对应于“此按钮”链接,则 php 应用此类。
$currentpath = basename(__FILE__);
在我包含 header.php 之前在每个页面上设置
谢谢!
PHP 和 HTML:
<?h
$o = "/ita/o.h";
$ = "/ita/.h";
$a = "/ita/a.h";
$s = "/ita/s.h";
$st = "/ita/st.h";
$p = "/ita/p";
$t = "/ita/t";
$c = "/ita/c";
?>
<div id="button">
<ul>
<li><a href=<?=$o?> class="<?php if($currentpath == basename($o)){echo("buttonon");} ?>">o</a></li>
<li><a href=<?=$p?> class="<?php if($currentpath == basename($p)){echo("buttonon");} ?>">p</a></li>
<li><a href=<?=$a?> class="<?php if($currentpath == basename($a)){echo("buttonon");} ?>">a</a></li>
<li><a href=<?=$s?> class="<?php if($currentpath == basename($s)){echo("buttonon");} ?>">s</a></li>
<li><a href=<?=$st?> class="<?php if($currentpath == basename($st)){echo("buttonon");} ?>">st</a></li>
<li><a href=<?=$p?> class="<?php if($currentpath == basename($p)){echo("buttonon");} ?>">p</a></li>
<li><a href=<?=$t?> class="<?php if($currentpath == basename($t)){echo("buttonon");} ?>">t</a></li>
<li><a href=<?=$c?> class="<?php if($currentpath == basename($c)){echo("buttonon");} ?>">c</a></li>
</ul>
</div>
CSS:
#button ul {
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
background-color: #F00;
}
#button ul li {
display: inline;
}
#button ul li a {
display:inline-block;
color:#FFF;
font-family:Calibri;
font-size:18px;
font-weight:bold;
padding:4px 15px 4px 15px;
text-decoration:none;
font-variant:small-caps;
}
#button ul li a:hover {
background-color:#F00;
color:#02346F;
padding:4px 15px 4px 15px;
font-size:18px;
font-weight:bolder;
}
.buttonon {
background-color:#F00;
display:inline-block;
font-family:Calibri;
font-size:18px;
font-weight:bold;
text-decoration:none;
font-variant:small-caps;
color:#02346F;
padding:4px 15px 4px 15px;
font-size:18px;
font-weight:bolder;
}
编辑:我添加了 $currentpath 的定义。