[{"id":"cssint-001","courseId":"css-intermediate","domain":"selectors-cascade","topic":"Attribute selector on an id","prompt":"A teammate rewrote a legacy rule with an attribute selector, expecting it to tie with the ID rule so the later one wins. The nav links stay red. Why?","hint":"Ask which column an attribute selector adds to, whatever attribute it names.","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Cascade/Specificity#class_column","interaction":{"type":"single"},"options":[{"id":"a","text":"Blue should win; the browser caches the first matching rule.","whyNot":"There is no such caching; the cascade compares specificity, then order."},{"id":"b","text":"[id=\"nav\"] is 1-0-1 like #nav, and red wins as the first declared.","whyNot":"When specificity ties, the later rule wins, not the first."},{"id":"c","text":"[id=\"nav\"] a is 0-1-1, so #nav a at 1-0-1 wins whatever the order.","why":"An attribute selector counts in the class column even when it names id, so the ID rule is more specific."},{"id":"d","text":"Attribute selectors carry no specificity, like :where().","whyNot":"Attribute selectors add 0-1-0, the same as a class."}],"answer":"c","explanation":"An attribute selector such as [id=\"nav\"] weighs like a class (0-1-0), even though it matches by id; only #nav adds to the ID column.","concept":"An attribute selector such as [id=\"nav\"] weighs like a class (0-1-0), even though it matches by id; only #nav adds to the ID column.","rev":1,"kind":"scenario","code":"#nav a { color: red; }\n\n[id=\"nav\"] a { color: blue; }","takeaways":["[id=\"x\"] weighs like a class; #x weighs like an ID."]},{"id":"cssint-002","courseId":"css-intermediate","domain":"selectors-cascade","topic":":root vs html specificity","prompt":"base.css sets :root { --brand: navy; }. A theme file loaded after it sets html { --brand: teal; } to rebrand the site, but buttons using var(--brand) stay navy. Why?","hint":"Both select the same element; compare how much each selector weighs.","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:root","interaction":{"type":"single"},"options":[{"id":"a","text":"Custom properties ignore later files, so the first declaration always sticks","whyNot":"Custom properties cascade like any property; a later rule of equal or higher specificity would win."},{"id":"b","text":":root is a pseudo-class worth 0-1-0, which beats the html type selector's 0-0-1","why":":root matches the same html element but with class-level specificity, so it wins before source order is considered."},{"id":"c","text":"var() reads the value from the first stylesheet that defines the property","whyNot":"var() uses the element's computed value, which comes from the normal cascade, not from file order."},{"id":"d","text":"html only matches in XML documents, so the theme rule never applies","whyNot":"In HTML, html matches the root element; the rule applies but loses on specificity."}],"answer":"b","explanation":":root and html select the same element in HTML, but :root has pseudo-class specificity (0-1-0) and beats html (0-0-1) regardless of order.","concept":":root and html select the same element in HTML, but :root has pseudo-class specificity (0-1-0) and beats html (0-0-1) regardless of order.","rev":1,"kind":"scenario","code":"/* base.css, loaded first */\n:root { --brand: navy; }\n\n/* theme.css, loaded last */\nhtml { --brand: teal; }","takeaways":["Override :root variables with :root, not html."]},{"id":"cssint-003","courseId":"css-intermediate","domain":"selectors-cascade","topic":":is() takes its heaviest argument","prompt":"A refactor grouped two selectors with :is(). Now paragraphs in .card ignore the .card p.lead rule and stay grey. What went wrong?","hint":"Ask what weight the grouped selector carries for every element it matches.","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#the_is_not_has_and_css_nesting_exceptions","interaction":{"type":"single"},"options":[{"id":"a","text":":is() is forgiving, so the .card p.lead rule is silently dropped.","whyNot":"Forgiving parsing only drops invalid selectors inside :is(); the other rule is valid and still applies."},{"id":"b","text":":is() uses the specificity of the argument that matched, so it should be 0-1-1.","whyNot":"This is the common misconception; the weight does not depend on which argument matched."},{"id":"c","text":"The grey rule comes first, so the later black rule should win; it is a caching bug.","whyNot":"Order is only a tie-breaker, and the two rules do not tie."},{"id":"d","text":":is() takes its most specific argument, so the grey rule weighs 1-0-1 even for .card.","why":"#hero gives the whole :is() an ID weight for every match, so 1-0-1 beats 0-1-2."}],"answer":"d","explanation":":is(), :not() and :has() take the specificity of their most specific argument, regardless of which argument actually matched.","concept":":is(), :not() and :has() take the specificity of their most specific argument, regardless of which argument actually matched.","rev":1,"kind":"scenario","code":":is(#hero, .card) p {\n  color: grey;\n}\n\n.card p.lead {\n  color: black;\n}","takeaways":["Never group an ID with classes in :is(); it lifts every match to ID weight."]},{"id":"cssint-004","courseId":"css-intermediate","domain":"selectors-cascade","topic":"Unlayered styles beat layers","prompt":"Your team moved the design system into @layer components. A one-off rule written outside any layer, with a weaker selector, now overrides the component's colour. A reviewer asks why. What is the answer?","hint":"Layers are compared before selectors are.","source":"https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Cascade_layers","interaction":{"type":"single"},"options":[{"id":"a","text":"Normal unlayered declarations outrank every layer, whatever their specificity.","why":"Layer precedence is checked before specificity, and unlayered normal styles come above all named layers."},{"id":"b","text":"The button rule wins because it appears later in the file.","whyNot":"Order of appearance is the last tie-breaker and never runs here; the layer check already decided."},{"id":"c","text":"Type selectors get a bonus when they are outside a layer.","whyNot":"There is no such bonus; specificity is unchanged, it is just not compared across layers."},{"id":"d","text":"Layers apply only to stylesheets loaded with @import.","whyNot":"@layer blocks work inline in any stylesheet, not only through @import."}],"answer":"a","explanation":"With cascade layers, normal unlayered styles beat layered ones, and specificity only matters within the same layer.","concept":"With cascade layers, normal unlayered styles beat layered ones, and specificity only matters within the same layer.","rev":1,"kind":"scenario","code":"@layer components {\n  .btn.btn-primary { color: white; }\n}\n\nbutton { color: black; }","takeaways":["Put resets and libraries in layers; app overrides then win without specificity tricks."]},{"id":"cssint-005","courseId":"css-intermediate","domain":"selectors-cascade","topic":"@import into a cascade layer","prompt":"A team wants a vendor stylesheet in a low-priority layer. They add the line below after their own .btn rule, and none of the vendor styles ever apply. What is wrong?","hint":"Think about where in a stylesheet an @import is allowed to sit.","source":"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@import","interaction":{"type":"single"},"options":[{"id":"a","text":"layer(vendor) needs a matching @layer vendor block first.","whyNot":"@import with layer() creates the layer if it does not exist yet."},{"id":"b","text":"Imported layers always lose to unlayered styles, so vendor rules never show.","whyNot":"They lose conflicts, but non-conflicting vendor rules would still apply."},{"id":"c","text":"The @import comes after a style rule, so the browser ignores it.","why":"@import must come before every rule except @charset and @layer statements; placed later, it is ignored."},{"id":"d","text":"layer() only accepts anonymous layers when used in @import.","whyNot":"Both named, as in layer(utilities), and unnamed layers are allowed."}],"answer":"c","explanation":"@import ... layer(name) puts an external stylesheet into a cascade layer, but like any @import it must sit at the top, after only @charset and @layer statements.","concept":"@import ... layer(name) puts an external stylesheet into a cascade layer, but like any @import it must sit at the top, after only @charset and @layer statements.","rev":1,"kind":"scenario","code":".btn { color: white; }\n\n@import url(\"vendor.css\") layer(vendor);","takeaways":["Put @layer order and @import ... layer() at the very top of the file."]}]