日期:2014-05-16  浏览次数:20600 次

关于链接和鼠标移上去的文字颜色问题

首先效果如图。

CSS:
#nav li{
width:70px;
float:left;
position:relative;
z-index:1;
height:38px;
display:table;
margin-right:10px;
}
#nav li a{
color:#d0f6d1;
font-size:12px;
font-weight:bolder;
display: block;
height:38px;
line-height:10px;
vertical-align:middle;   
    display:table-cell;
font-family:"黑体";
line-height:110%;
}
#nav li a:hover{
background:url(nav_a_bg.png) center no-repeat;
color:#329a07;
}
a.this{
color:#329a07;
background:url(nav_a_bg.png) center no-repeat;
}

HTML就是单纯的li和a了
<li><a href="#" class="this">首页<br />Home</a></li>
   <li><a href="#">公司简介<br />AboutUs</a></li>


目前主要是class="this"就是目前是在哪个栏目。
不知道为什么color不生效,背景图片是没有问题的。
鼠标移动到栏目上,字是会变成绿色,本来应该this的color生效,字也应该是绿色的才对啊。
求大神们解惑。

------解决方案--------------------
css有覆盖顺序的,this里的a被#nav li a覆盖了。 提高一下this样式里的颜色的优先级就行,如下。

  a.this
        {
            background: url(nav_a_bg.png) center no-repeat;
            color: #329a07 !important
        }

------解决方案--------------------
因为上面#nav li a比a.this更具体,所以优先 
a.this{
color:#329a07;
background:url(nav_a_bg.png) center no-repeat;
}
 改成 
#nav li a.this {
color:#329a07;
background:url(nav_a_bg.png) center no-repeat;
}
------解决方案--------------------
另外,不是很建议用this之类的关键字做样式的名称,或者像new,object之类的,虽然我也不知道有没有什么潜在的问题。。,有高手在的话希望帮忙解答一下。

比如你可以用a.current。