How Can I Effectively Override CSS Text Decoration Inheritance?
Understanding CSS Text Decoration Inheritance
In CSS, overriding text decoration can be a challenge. When a parent element with a text-decoration style is applied, it inherits its decoration to all its child elements. This can cause confusion when trying to control the decoration of specific elements.
The Case of Overriding Text Decoration
Consider the example provided, where the following CSS is used:
ul > li { text-decoration: none; } ul > li.u { text-decoration: underline; } ul > li > ul > li { text-decoration: none; } ul > li > ul > li.u { text-decoration: underline; }
And the HTML is as follows:
<ul> <li>Should not be underlined</li> <li class="u">Should be underlined <ul> <li>Should not be underlined</li> <li class="u">Should be underlined</li> </ul> </li> </ul>
Here, the expected behavior is that the nested list items would receive no decoration, while the parent items with the u class would be underlined. However, the result shows that all list items are underlined.
The Explanation
The reason for this behavior lies in the nature of CSS text decoration. Unlike other font properties, text-decoration applies to the entire element, including all nested elements. This means that the decoration defined in the parent container applies recursively to its children, regardless of their own text-decoration styles.
This behavior is documented in the CSS21 specification:
Text decorations on inline boxes are drawn across the entire element, going across any descendant elements without paying any attention to their presence. The 'text-decoration' property on descendant elements cannot have any effect on the decoration of the element.
Conclusion
Overriding text decoration in CSS requires understanding this inheritance behavior. To ensure that specific elements do not inherit the decoration from their parent, it is necessary to define text-decoration: none for each level of the nesting.
The above is the detailed content of How Can I Effectively Override CSS Text Decoration Inheritance?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there's a bit of a learning curve, but Grid is

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
