Why does the browser apply a style to element (nesting selector)

2 days ago 4
ARTICLE AD BOX

I have a question about the MDN example (https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Nesting/Using#example_3):

.card { padding: 0.5rem; border: 1px solid black; border-radius: 0.5rem; & h2 { /* equivalent to `.card h2` */ color: slateblue; .featured & { /* equivalent to `:is(.card h2):is(.featured h2)` */ color: tomato; } } } <div class="wrapper"> <article class="card"> <h2>Card 1</h2> <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p> </article> <article class="card featured"> <h2>Card 2</h2> <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p> </article> <article class="card"> <h2>Card 3</h2> <p>Lorem ipsum dolor, sit amet consectetur adipisicing elit.</p> </article> </div>

As far as I understand the selector .featured & should be replaced by the browser with .featured .card h2

In other words, in order for the style to be applied, the h2 element must be nested in the element with class .card, which in turn is nested in the element with class .featured

But if you open this example in a browser, it turns out that this style is applied to the <h2>Card 2</h2> element, which is nested in <article class="card featured">

Why does the browser apply a style to this element?

The example also says that this style is equivalent to the style :is(.card h2):is(.featured h2)

As far as I understand :is(.card h2):is(.featured h2) will work for the <h2> element that is nested in the element with classes .card .featured, i.e. this style could be written as .card.featured h2?

Read Entire Article