Performance: Basic selector nesting
This affects CSS parsing and rendering speed by influencing how browsers match selectors to elements.
nav {
a {
color: blue;
text-decoration: none;
}
}nav ul li a {
color: blue;
text-decoration: none;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Deeply nested selectors | No extra DOM nodes | 0 | Higher due to slower style matching | [X] Bad |
| Shallow nesting with simple selectors | No extra DOM nodes | 0 | Lower due to faster style matching | [OK] Good |
& symbol represent in Sass nesting?& in Sass& symbol is used inside nested selectors to refer to the parent selector.& helps avoid repeating the parent selector by representing it directly.& means parent selector [OK].button class inside a .container class?.button inside .container using braces. Options B and C are plain CSS selectors, not Sass nesting. .container, .button { color: blue; } combines selectors incorrectly..nav {
ul {
margin: 0;
li {
list-style: none;
}
}
}ul is nested inside .nav, so the selector becomes .nav ul. The li is nested inside ul, so it becomes .nav ul li..card {
&.active {
background: green;
}
.title {
font-weight: bold;
}
& .subtitle {
font-size: 1.2rem;
}
}& .subtitle selector& means it selects .card .subtitle. This is different from &.subtitle which selects .card.subtitle.& usage with classes is valid, and nesting .title inside .card is correct.& .subtitle adds an unwanted space, changing meaning. -> Option B.card only when the card is .active. Which Sass nesting produces the correct CSS selector .card.active button?.card.active button means a button inside a .card that also has the .active class.button inside &.active inside .card, producing .card.active button. Other options either place .active on the button or use incorrect nesting.Pass the test and this pattern moves unknown