2011-11-03 122 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