Home >Web Front-end >CSS Tutorial >Can Child Elements Override the CSS `text-decoration` Property?
Overriding CSS text-decoration Property in Child Elements
In CSS, certain properties can be overridden by child elements, while others cannot. The text-decoration property falls into the latter category.
When applied to a parent element, text-decoration affects the entire element, including any descendant elements. This means that child elements cannot override the text-decoration property of their ancestors.
According to the CSS text-decoration specification:
"The 'text-decoration' property on descendant elements cannot have any effect on the decoration of the ancestor."
This is because text decorations are drawn across the entire parent element, ignoring any descendant elements.
Understanding Overridable Properties
CSS properties that can be overridden by child elements generally fall into the following categories:
Properties that cannot be overridden by child elements include:
CSS3 text-decoration-skip Property
In CSS3, a new property called text-decoration-skip was introduced to address limitations with text-decoration overriding. This property allows child elements to skip over specific types of text decoration applied to their ancestors.
For example:
span { text-decoration-skip: underlines; }
By setting text-decoration-skip to "underlines", the span element will skip any underlined text decoration applied to its parent element.
The above is the detailed content of Can Child Elements Override the CSS `text-decoration` Property?. For more information, please follow other related articles on the PHP Chinese website!