I want to override the parent css in child element. I want to underline the parent element, but not the child element.
.parent {
text-decoration: underline;
color: red;
}
.child {
color: green;
text-decoration: none !important;
}
.sub-child {
color: green;
text-decoration: none !important;
}
<div class="parent">Inside parent
<div class="child">Inside first child
<div class="sub-child">Inside 1st child of 1st child
</div>
</div>
<div class="child">Inside 2nd child
<div class="sub-child">Inside 1st child of 2nd child</div>
<div class="sub-child">Inside 2nd child of 2nd child</div>
</div>
<div class="child">
Inside 3rd child
<div class="sub-child">Insde 1st child of 3rd child</div>
</div>
</div>
The text-decoration-skip CSS property sets what parts of an element's content any text decoration affecting the element must skip over. It controls all text decoration lines drawn by the element and also any text decoration lines drawn by its ancestors.
Description. This property specifies the decorations that will be applied to the text content of an element. These decorations are rendered in the color specified by the element's color property. The text decorations are not technically inherited, but the effect is similar to inheritance.
The style rule em { text-decoration: none; } would not cause any change; the entire paragraph would still be underlined. However, the rule em { text-decoration: overline; } would cause a second decoration to appear on "some emphasized words".
By setting the text-decoration to none to remove the underline from anchor tag. Syntax: text-decoration: none; Example 1: This example sets the text-decoration property to none.
As stated in MDN
Text decorations draw across descendant elements. This means that it is not possible to disable on a descendant a text decoration that is specified on one of its ancestors.
So, unfortunately, you can't. The only solution is, as others stated here, to wrap the corresponding text with a tag e.g. a span
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With