This exercise uses selectors that target elements which are direct children of parent elements. Can we similarly target more deeply nested elements?


#1

Question

This exercise uses selectors that target elements which are direct children of parent elements. Can we similarly target more deeply nested elements?

Answer

Yes we can target deeply nested child elements. While we can target arbitrarily nested elements with the descendant selector, in practice we should aim to keep our selectors short. As a very general rule of thumb, if our descendant selectors start to become greater than 3 levels deep we may want to consider ways to more specifically target the element in question. For example, perhaps we can throw a class on the targeted element instead of using a deeply nested selector.


FAQ: Learn CSS Selectors Visual Rules - CSS Setup Selectors - Nested Elements