Descendant vs Child Combinators in CSS
The descendant combinator (space) selects all elements that are nested anywhere within a specified parent, while the direct child combinator (>) selects only elements that are immediate children of the parent.
Descendant combinator: A B selects all B elements inside A at any depth.
Child combinator: A > B selects only B elements that are direct children of A.
Using multiple descendant selectors in a chain (e.g., div ul li a) increases specificity and targets elements deeply nested in the hierarchy.
Excessive chaining can reduce CSS maintainability and may impact performance if overused in large DOMs.
We have a navigation bar with <ul><li> items and you need to style all <a> tags inside any <li>. How would you write the selector? What would happen if you used a child combinator instead?
Given HTML <div class='card'><p><span>Text</span></p></div>, you want to target the <span>. Write a selector using a descendant combinator and explain why it works.
Your team added a new component inside a modal, and the existing CSS rule '.modal .content p' stopped applying. Walk me through how you would debug the selector chain and decide whether to use a descendant or child combinator.
We need to style all buttons inside any form, but exclude buttons that are direct children of the form. How would you craft the selector, and what trade‑offs does this introduce for maintainability?
In a large e‑commerce site, you notice that deep descendant selectors like '.catalog .category .item .price' are causing rendering slowdowns on low‑end devices. How would you assess the performance impact and refactor the CSS architecture?
Your design system enforces a rule to avoid more than three levels of descendant selectors. Explain how you would enforce this rule across multiple teams and what fallback strategies you’d use if a legacy component violates it.
Our company is migrating a monolithic CSS codebase to a utility‑first framework. How would you handle existing complex descendant selector chains to ensure they don’t break the new system, and what long‑term strategy would you propose for selector hygiene?
Cross‑team, we have a shared component library where some components rely on deep descendant selectors for theming. Discuss the architectural implications of keeping those selectors versus refactoring to CSS custom properties or BEM, considering future scalability.