Descendant selectors

Renaming elements with classes, as you learned in the previous section, is an extremely powerful feature in CSS. However, that's not the only way to target a specific type of element. Descendant selectors will allow you to target elements on a page based on their ancestor elements. This is often necessary because you only want to apply a margin or a new font based on the context of the element. You can use a descendant selector to get that context without putting a class on every element every time you want to target it. I'm going to first explain what parent, sibling, and child elements are as well as what ancestor and descendant elements are. We'll need to be clear about these if we want to use descendant selectors. ...

Get Mastering CSS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.