我正在使用PHP,HTML和CSS开发网站。目前在我的导航栏中,我将背景颜色设置为灰色。当用户将鼠标悬停在导航栏上时,每个链接都会显示蓝色背景,但是当我单击该链接时,背景颜色会变回灰色。如果该特定链接处于活动状态,如何使悬停颜色保持蓝色。
这是我导航栏的代码。
<tr>
<td width="800" height="54">
<div id="nav" >
<ax><b><font face="Arial" ><a style="text-decoration: none; color:#303030" href="index.php" >HOME</a></font></b></ax>
<bx><b><font face="arial" ><a style="text-decoration: none; color:#303030" href="edituser.php?own=y">IT</a></font></b></bx>
<cx><b><font face="arial" ><a style="text-decoration: none; color:#303030" href="newsevents.php">HUMAN RESOURCE</a></font></b></cx>
<dx><b><font face="arial" ><a style="text-decoration: none; color:#303030" href="industries.php">PROCUREMENT</a></font></b></dx>
<ex><b><font face="arial" size="1"><a style="text-decoration: none; color:#303030" href="http://www.csmphilippines.com/aboutus.html">FINANCE</a></font></b></ex>
<fx><b><font face="arial" ><a style="text-decoration: none; color:#303030" href="hact.php">HACT</a></font></b></fx>
</div>
</td>
这是我的CSS代码
#nav {
text-decoration:none;
padding-bottom:10px;
border-bottom:none;
width:
}
#nav ax {
display:inline;
padding:15px;
padding-left:31px;
padding-right:28px;
background-color:#ececec;
text-decoration:none;
}
#nav bx {
display:inline;
padding:15px;
padding-left:45px;
padding-right:45px;
background-color:#ececec;
text-decoration:none;
}
#nav cx {
display:inline;
padding:15px;
padding-left:45px;
padding-right:45px;
background-color:#ececec;
text-decoration:none;
}
#nav dx {
display:inline;
padding:15px;
padding-left:45px;
padding-right:45px;
background-color:#ececec;
text-decoration:none;
}
#nav ex {
display:inline;
padding:15px;
padding-left:53px;
padding-right:53px;
background-color:#ececec;
text-decoration:none;
}
#nav fx {
display:inline;
padding:15px;
padding-left:30px;
padding-right:30px;
background-color:#ececec;
text-decoration:none;
}
#nav ax:hover {
background-image:url(images/tabbackit.jpg);
background-repeat:repeat-x;
height:900px;
}
#nav bx:hover {
background-image:url(images/tabbackit.jpg);
background-repeat:repeat-x;
height:900px;
}
#nav cx:hover {
background-image:url(images/tabback.jpg);
background-repeat:repeat-x;
height:900px;
}
#nav dx:hover {
background-image:url(images/tabbackproc.jpg);
background-repeat:repeat-x;
height:900px;
}
#nav ex:hover {
background-image:url(images/tabbackfin.jpg);
background-repeat:repeat-x;
height:900px;
}
#nav fx:hover {
background-image:url(images/tabbackhact.jpg);
background-repeat:repeat-x;
height:900px;
}
答案 0 :(得分:0)
我这样做的方法是在body标签中为每个页面提供自己的id:
<body id="pgAbout">
然后为每个菜单项设置一个单独的id:
<li id="mnuAbout">
使用CSS,您可以为您所在的页面设置链接的样式:
#pgAbout #mnuAbout,
#pgOther #mnuOther
{
/* Styles here */
}
<强>更新强>
Here's another demo使用您自己的HTML来澄清它是如何运作的。
答案 1 :(得分:0)
您可以做的一件简单事情是为所有页面使用相同的样式表,但使用不同的CSS类来突出显示每个页面上的相应链接。例如,在index.php上,使用.active
类突出显示Home链接。
既然你是新人(如你所说),让我们分解一下:
对所有页面使用相同的CSS。但是,为导航栏元素定义两个CSS类:一个是.regular
状态,另一个是.active
状态。在每个页面中,将与该页面对应的链接指定为活动类,而其他链接保留在常规类中。
但是,那么,您是否希望保持链接?
答案 2 :(得分:0)
这很简单,只需输入以下代码即可 例如, 在主页上,将以下代码放在HEAD中
<style type="text/css">
#nav ax{
background-image:url(images/tabbackit.jpg);
background-repeat:repeat-x;
}
</style>