[{"id":"cssadv-001","courseId":"css-advanced","domain":"selectors-cascade","topic":"Nested cascade layers","prompt":"A framework ships its CSS in one layer with two nested layers, plus a rule written directly in the framework layer. All three selectors are plain a. What color are links?","hint":"Inside a layer, compare rules that sit in a nested layer with rules that do not.","source":"https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Cascade_layers","interaction":{"type":"single"},"options":[{"id":"a","text":"Blue, because components is the last nested layer and later layers win","whyNot":"Later nested layers do beat earlier ones, but the framework layer's own rule beats both."},{"id":"b","text":"Gray, because the first nested layer declared keeps priority for normal rules","whyNot":"For normal declarations, earlier layers lose to later ones, not the other way round."},{"id":"c","text":"Green, because a layer's own non-nested rules beat its nested layers' normal rules","why":"Within a layer, non-nested styles take precedence over normal styles in its nested layers, like unlayered styles over layers at the top level."},{"id":"d","text":"Blue, because the three rules tie on specificity and that rule comes last","whyNot":"Layer precedence is settled before specificity or order of appearance is compared."}],"answer":"c","explanation":"Nested layers work like layers one level down: their order is the order they were created, and the parent layer's own non-nested rules beat all its nested normal rules.","concept":"Nested layers work like layers one level down: their order is the order they were created, and the parent layer's own non-nested rules beat all its nested normal rules.","rev":1,"kind":"scenario","code":"@layer framework {\n  @layer base, components;\n  a { color: green; }\n}\n@layer framework.base {\n  a { color: gray; }\n}\n@layer framework.components {\n  a { color: blue; }\n}","takeaways":["Inside a layer, rules outside its nested layers win, just as unlayered rules win at the top."]},{"id":"cssadv-002","courseId":"css-advanced","domain":"selectors-cascade","topic":"!important reverses layer order","prompt":"A design system declares @layer reset, components. The reset layer has [hidden] { display: none !important; } and the components layer has .card { display: flex !important; }. A div has class card and the hidden attribute. What happens?","hint":"Think about which layers important declarations favour.","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Cascade/Introduction","interaction":{"type":"single"},"options":[{"id":"a","text":"The card shows as flex, because components is the later layer and later layers win","whyNot":"Later layers win only for normal declarations; for important ones the order flips."},{"id":"b","text":"The card shows as flex, because both selectors weigh 0-1-0 and the components rule comes later","whyNot":"Layer order is settled before specificity or source order are compared."},{"id":"c","text":"The card stays hidden, because important declarations in earlier layers beat those in later layers","why":"!important reverses layer precedence, so the reset layer's important rule wins. This lets low layers protect rules that later layers must not undo."},{"id":"d","text":"The card stays hidden, because the browser's own display: none for hidden outranks author CSS","whyNot":"The browser's rule for hidden is a normal user-agent declaration that author styles override; the reset's important rule is what wins."}],"answer":"c","explanation":"Important declarations sort layers in reverse: earlier layers beat later ones, and layered important styles beat unlayered important ones.","concept":"Important declarations sort layers in reverse: earlier layers beat later ones, and layered important styles beat unlayered important ones.","rev":1,"kind":"scenario","takeaways":["!important in an early layer is a lock that later layers cannot pick, which is useful for resets and accessibility rules."]},{"id":"cssadv-003","courseId":"css-advanced","domain":"selectors-cascade","topic":":nth-child() with of S","prompt":"A task list hides finished items with .done { display: none; } and stripes rows with li:nth-child(even). With some tasks done, the stripes no longer alternate on screen. Which selector stripes every second visible task?","hint":"Hidden items still count as siblings unless the selector filters them out before counting.","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:nth-child","interaction":{"type":"single"},"options":[{"id":"a","text":"li:not(.done):nth-child(even)","whyNot":"This still counts every li, done or not, and then drops the done ones, so gaps remain."},{"id":"b","text":"li:nth-of-type(even)","whyNot":"nth-of-type counts every li sibling, including the hidden ones."},{"id":"c","text":"li:nth-last-child(even)","whyNot":"Counting from the end changes the direction, not which siblings are counted."},{"id":"d","text":"li:nth-child(even of :not(.done))","why":"With of S, only siblings that match S are counted, so the stripes follow the visible tasks."}],"answer":"d","explanation":":nth-child(An+B of S) counts only the siblings that match S, while S:nth-child(An+B) counts all siblings and then filters.","concept":":nth-child(An+B of S) counts only the siblings that match S, while S:nth-child(An+B) counts all siblings and then filters.","rev":1,"kind":"scenario","takeaways":["Put the filter inside :nth-child(... of S) to change what gets counted."]},{"id":"cssadv-004","courseId":"css-advanced","domain":"selectors-cascade","topic":"@scope with a scope limit","prompt":"A card's header has a thumbnail, and its .card-content area holds images that users embed. The team writes the rule below. Which images get the border?","hint":"The scope root is an upper bound and the to selector a lower bound. Which bound is inclusive?","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@scope","interaction":{"type":"single"},"options":[{"id":"a","text":"Only images inside .card that are not inside .card-content","why":"The scope limit is exclusive: the .card-content element and everything inside it fall outside the scope."},{"id":"b","text":"Every image inside .card, since to only lowers the rule's specificity","whyNot":"The limit changes which elements match, not how much the rule weighs."},{"id":"c","text":"Only images inside .card-content, the part of the card the limit names","whyNot":"That reverses it: the limit marks where the scope stops."},{"id":"d","text":"Every image in .card, but those in .card-content can be overridden by any class","whyNot":"Images under the limit are not matched at all, so there is nothing to override."}],"answer":"a","explanation":"@scope (root) to (limit) styles the subtree from the root down to, but not including, the limit, which makes a donut scope that skips nested content.","concept":"@scope (root) to (limit) styles the subtree from the root down to, but not including, the limit, which makes a donut scope that skips nested content.","rev":1,"kind":"scenario","code":"@scope (.card) to (.card-content) {\n  img { border: 2px solid; }\n}","takeaways":["@scope (.a) to (.b) stops at .b: the limit and its subtree are left out."]},{"id":"cssadv-005","courseId":"css-advanced","domain":"selectors-cascade","topic":"Forgiving selector lists","prompt":"A form uses .field:user-invalid, .field.error { outline: 2px solid red; }. In a browser that does not know :user-invalid, fields with the error class lose their outline too. Why, and what is the fix?","hint":"What does one unknown selector do to a plain comma-separated list?","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:is","interaction":{"type":"single"},"options":[{"id":"a","text":"The browser drops the outline when any selector in the list matches nothing; add !important","whyNot":"A selector that matches nothing is harmless; the issue is that it fails to parse, and !important does not fix parsing."},{"id":"b","text":"Unknown pseudo-classes make the browser fall back to its default focus outline; set outline-style","whyNot":"No fallback happens; the rule is thrown away before any outline applies."},{"id":"c","text":"An invalid selector makes the whole list invalid; wrap it as .field:is(:user-invalid, .error)","why":"Plain selector lists are unforgiving, so one unsupported selector drops the rule. :is() takes a forgiving list, ignoring the unknown part and keeping the rest."},{"id":"d","text":"Compound selectors such as .field.error are not allowed in a list with pseudo-classes; split by type","whyNot":"Any mix of compound selectors is allowed in a list; the unknown pseudo-class is the problem."}],"answer":"c","explanation":"A plain selector list is invalidated by a single unparseable selector, while :is() and :where() ignore the invalid argument and keep the others.","concept":"A plain selector list is invalidated by a single unparseable selector, while :is() and :where() ignore the invalid argument and keep the others.","rev":1,"kind":"scenario","takeaways":["Group new or experimental selectors inside :is() or :where() so one unknown selector cannot kill the rule."]}]