HTML
<ul>
<li><a href="#">Messages<span>1</span></a></li>
</ul>
CSS
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:hover span {
text-decoration: none;
}
span {
background-color: red;
border-radius: 999px;
color: white;
margin-left: 2px;
position: relative;
top: -.5em;
font-size: .75em;
font-weight: bold;
padding: 0 .3em;
}
When you mouse-over the link the underline is applied to the <span>
even though I've set text-decoration: none
. Is there a way to get rid of it?
Try changing the
display
of<span>
toinline-block
as follows:Example Here
Explanation
According to CSS level 2 specification,
text-decoration
is not propagated to the contents of nested atomic inline-level elements - such as inline-blocks and inline-tables.Also the spec states (my emphasis):
Also note that text decorations would stick with the text itself, therefore: