Why doesn't the CSS property text-decoration: none work within a paragraph?
In summary; Text decorations that are applied to parent elements cannot be removed from descendant elements, unless in specific cases where they are not inherited.
This scenario is explained in detail on MDN: (emphasis added)
Text decorations extend across child elements, meaning it's impossible to disable a text decoration set by an ancestor element on its children.
For instance, consider this code:
<p>This text has <em>some emphasized words</em> in it.</p>
,
If the style rule is
p { text-decoration: underline; }
, the entire paragraph will be underlined. The subsequent rule em { text-decoration: none; }
won't have any effect; the entire paragraph remains underlined.
However, there are exceptions where text decorations do not pass down to child elements - refer to the W3C specification on the 'text-decoration' property for more details
Note that text decorations do not cascade to floating and
absolutely positioned descendants or to the contents of atomic
inline-level descendants like inline blocks and inline tables.
Hence, if the span element has
1) display: inline-block
, or
2) is floated or
3) is absolutely positioned then
the text decorations don't propagate to it initially. (this also implies that text-decoration: none;
isn't needed)
p {
color:red;
text-decoration:
underline;
font-size: 1.2em;
}
span.none {
display: inline-block;
}
<p class="p">Click the thumb<span class="none">!</span></p>