2011-11-03 129 views
1

我的CSS是这样的:重写链接样式

A:link { text-decoration: none; color: White; border-bottom:1px dotted white; font-style:italic;} 
A:visited { text-decoration: none; color: White; border-bottom:1px dotted white; font-style:italic;} 
A:active { text-decoration: none; color: White; border-bottom:1px dotted white; font-style:italic;} 
A:hover { text-decoration: none; color: white; border-bottom:1px solid white; font-style:italic; } 

#mainmenu A:link { text-decoration: none; } 
#mainmenu A:visited { text-decoration: none; } 
#mainmenu A:active { text-decoration: none; } 
#mainmenu A:hover { text-decoration: underline; color: white; } 

和HTML我有:

<div id="mainmenu"> 
    <a href="link here">link</a> 
</div> 

我会认为这菜单项将有没有文字的装饰风格,而是它获取下划线的风格。所以#mainmenu的样式似乎被忽略,它总是采用默认样式。

我错过了什么吗?

+0

什么broswer你在查看此? –

+0

firefox 7,但在IE中相同 –

+0

'#id'样式优先于'.class'样式,它优先于'a'对象样式。你可能想让自己了解层叠样式表的层叠部分:) –

回答

1

http://jsfiddle.net/CU9RH/1/表明#mainmenu链接没有下划线,但有一个底部虚线边框。

你需要覆盖底部边框,如果你想让它不显示:

#mainmenu A:link { text-decoration: none; border-bottom:none;} 
#mainmenu A:visited { text-decoration: none; border-bottom:none;} 
#mainmenu A:active { text-decoration: none; border-bottom:none;} 

示范与修复:http://jsfiddle.net/uYhtw/1/

+0

好吧,那样做!我需要专门设置下边框为无!谢谢!! –

1

好奇,CSS是区分大小写的(至少在类名和标识符),据我所知,这将是与“自然元素”太多 - 但无论如何,您可以覆盖使用!important关键字样式:

#mainmenu a:link { text-decoration: none !important; } 
+0

你击败了我的编辑到拳击问题= P –

+1

应该指出,它取决于文档类型和浏览器,只要区分大小写。 XML或XHTML doctypes将强制区分大小写。你不得不阅读其他潜在的文档类型,因为我不确定;) –

+0

@PaulZaczkowski好点和yep,绝对值得做这项研究。 –

1

这是你的代码

#mainmenu A:hover { text-decoration: underline; color: white; } 

A:hover { text-decoration: none; color: white; border-bottom:1px solid white; font-style:italic; } 

#mainmenu被设置下划线和颜色,所以,如果你想#mainmenu不具有下划线,那么你需要更改您的代码

不是被忽视
#mainmenu A:hover { text-decoration: none; color: white; border: 0; } 

A:hover { text-decoration: underline; color: white; border-bottom:1px solid white; font-style:italic; } 
+0

这是国家_other than_悬停哪OP想压制文字修饰。 –

+0

@ Mr.Disappointment我正在输入OP的代码,因为他有。显示错误,我还没有完成编辑它 – CBRRacer