Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css and underline

Tags:

css

Why is the link using the underline?

<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>
like image 970
user319854 Avatar asked Dec 21 '25 14:12

user319854


1 Answers

Because this is the default (user agent css have this rule, to apply underline in every tag a). The default isn't inherit, so even if parent tag has underline, the child won't get it.


EDIT 1:

For example, firefox have this rule:

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

Default would be:

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

Then, in your example, the tag a would inherit div text-decoration.


EDIT 2:

You can overwrite default behavior with:

a {
    text-decoration: inherit;
}
like image 138
Topera Avatar answered Dec 23 '25 10:12

Topera