为什么链接使用下划线?
<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>
最佳答案
因为这是默认的(用户代理 css 有这个规则,在每个标签 a 中应用下划线)。默认不是inherit
,所以即使父标签有下划线,子标签也不会得到它。
编辑 1:
例如firefox有这个规则:
*|*:-moz-any-link {
text-decoration:underline;
}
默认为:
*|*:-moz-any-link {
text-decoration:inherit;
}
然后,在您的示例中,标签 a
将继承 div
text-decoration。
编辑 2:
您可以使用以下方式覆盖默认行为:
a {
text-decoration: inherit;
}
关于CSS 和下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3596427/