2010-08-29 147 views
3

爲什麼鏈接使用下劃線?css和下劃線

<html> 
<head> 
<style type="text/css"> 
body{ 
    text-decoration: underline; 
} 
#text{ 
    text-decoration: none; 
} 
</style> 
</head> 
<body> 
Text text text <br/> 
<div id = "text"> 
    <a href="#">link</a> 
</div> 
</body> 
</html> 
+0

哪個瀏覽器? – knittl 2010-08-29 20:19:35

回答

2

這是a標記的默認行爲。它不符合#text風格。

3

因爲這是默認的(用戶代理css有這條規則,所以在每個標籤a中應用下劃線)。默認不是inherit,所以即使父標籤有下劃線,孩子也不會得到它。


編輯1:

例如,火狐有這樣的規則:

*|*:-moz-any-link { 
    text-decoration:underline; 
} 

默認值是:

*|*:-moz-any-link { 
    text-decoration:inherit; 
} 

然後,在你的榜樣,標籤a將繼承div text-deco配給。


編輯2:

與您可以覆蓋默認行爲:

a { 
    text-decoration: inherit; 
} 
0

它包含在默認瀏覽器CSS。這只是好像這是之前你的風格標籤包括:

a{ 
    text-decoration: underline; 
} 

當然,鏈接也匹配#text,但由於a是更具體的,它贏了。瀏覽器的a(如font-size)未明確指定的任何屬性都將被繼承。

1

我想你想更換這個...

#text{ text-decoration: none; }

這... ...

#text a:link{ text-decoration:none; }

這告訴適用於那些對兒童所有錨規則標籤誰是id是'文字'