Paskins Loe Paskins Loe - 7 months ago 15
HTML Question

css "text-decoration: none" not working

I don't understand why the

text-decoration: none
does not work in the following code. It fails to remove the underline of the word
yes
.



.button {
color: black;
text-decoration: none;
}
body {
font-family: 'Roboto', 'Microsoft JhengHei', sans-serif;
font-size: 24px;
}

<a href="www.example.com">
<div class="button" id="yes">
Yes
</div>
</a>





As you can see from the example below, the child can override the parent. This is contradictory to the problem above.



.b {
color: black;
}
.c {
color: yellow;
}

<div class="b">
<div class="c">
abc
</div>
</div>




Answer

By default the a tag has underline effect (using text-decoration:underline), So to remove this, you must remove from a tag not from its child element.

If you are talking like color values can be overridden from parent to child element but why not text-decoration?

This is because the text-decoration property doesn't inherit the style from its parent element but relies upon its own element.

Check w3c reference.

Comments