我目前正在尝试为我的一个网站设计一个导航栏。此导航栏将位于网页顶部。
问题是当我将鼠标悬停在项目上时,我可以让项目改变颜色,但一旦页面处于活动状态,就无法让项目保持悬停状态。例如,如果我想去“主页”,我会将鼠标悬停在导航栏中的“主页”项上,当我单击它返回“index.php”时,它会变成灰色"在导航栏中将保持灰色。(导航栏的背景为黑色)。
我已经用一行和几条数据格式化了一个表格,这些数据将用作链接。这是 HTML 代码的样子:
<div id="header_banner">
<table id="header_banner_table">
<tr id="header_banner_row">
<td id="header_banner_a"><a class ="link1" href="">Item 1</a></td>
<td id="header_banner_b"><a class ="link1" href="">Item 2</a></td>
<td id="header_banner_c"><a class ="link1" href="">Item 3</a></td>
<td id="header_banner_d"><a class ="link1" href="">Item 4</a></td>
<td id="header_banner_e"><a class ="link1" href="">Item 5</a></td>
<td id="header_banner_f"><a class ="link1" href="">Item 6</a></td>
<td id="header_banner_g"><a class ="link1" href="">Item 7</a></td>
</tr>
</table>
</div>
这是一些CSS:
#header_banner {
display: block;
position: fixed;
top: 0px;
left: 0px;
right: 0px;
width: 100%;
height: 71px;
background-color: black;
color: white;
font-size: 18px;
text-align:center;
text-transform: uppercase;
text-decoration: none;
}
#header_banner_table {
position: fixed;
top: 0px;
width: 60%;
padding: 0px;
margin-left: 20%;
margin-right: 20%;
}
.link1 {
position: relative;
display: block;
color: white;
text-decoration: none;
padding-top: 23px;
padding-bottom: 23px;
padding-left: 20px;
padding-right: 20px;
}
.link1:hover{
position: relative;
display: block;
text-decoration: none;
color: white;
padding-top: 23px;
padding-bottom: 23px;
padding-left: 20px;
padding-right: 20px;
background-color: gray;
}
所以目前导航栏的背景是黑色的,当你将鼠标悬停在某个东西上时,它会变成灰色。当该页面处于活动状态时,我希望它保持灰色。
有什么解决办法吗?
先感谢您。