Child Combinator and Grandchild Elements
The child combinator (>) cannot select a grandchild element because it only targets elements that are direct children of the specified parent. Elements nested deeper than the first level are not matched.
Syntax: A > B – selects only immediate children B of parent A.
Grandchildren or deeper descendants require the descendant combinator (space) or additional selectors.
Using the child combinator ensures precise styling for direct children without affecting nested elements.
You’re trying to style only the direct children of a nav menu, but your styles are also hitting the links inside dropdowns. What’s the issue, and how do you fix it using the child combinator?
If you write .card > p, but the paragraph is inside a div inside the card, will it be styled? Why or why not?
A teammate says their CSS rule .list > li { color: blue; } isn’t working, but the HTML looks right. What are three possible reasons you’d check, and how would you isolate the issue?
We’re building a reusable card component where only top-level buttons should have padding, but nested buttons (like in a footer) shouldn’t. How would you use the child combinator to enforce this, and what edge cases might break it?
In a dynamic CMS-driven UI, content authors can nest components arbitrarily. How would you design a CSS architecture using the child combinator to ensure styling predictability without over-constraining flexibility?
You’re optimizing a legacy UI with 500+ CSS rules. You notice many descendant selectors (space) are causing unintended style leaks. How would you audit and refactor them using child combinators, and what risks would you mitigate?
We’re migrating from a legacy CSS framework that relies heavily on deep descendant selectors to a modern component-based system. How would you design a strategy to replace those with child combinators without breaking existing layouts across 20+ products?
When designing a design system for a global company, how do you balance the precision of child combinators against the need for composability in nested third-party widgets? What tradeoffs do you document for engineers?