2010-08-29 149 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是'文字'