In this guide in example section we have the following html structure:
<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>
...
</div>
and css applied:
.card {
padding: 0.5rem;
border: 1px solid black;
border-radius: 0.5rem;
& h2 {
/* equivalent to `.card h2` */
color: slateblue;
.featured & {
/* equivalent to `.featured .card h2` */
color: tomato;
}
}
}
My question about this css line
/* equivalent to
.featured .card h2
*/
How does it work? Since in the example the card element is not a child of feature element. But styles are still applied.
It should be like this
.featured.card h2
But then i don’t understand how nesting works in this particular case when we have several layers nested and & in the end of the selector. Could you please help.