From the course: CSS: Selectors

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Parent-child selectors

Parent-child selectors - CSS Tutorial

From the course: CSS: Selectors

Start my 1-month free trial

Parent-child selectors

- [Instructor] Parent-Child Selectors are very handy if you want to get the child element of a given parent. The Descendant Selector selects all of the descendants that match a given selector, but the Parent-Child Selector selects only this specific variety. So in this example, I've given you some HTML here where we have an article, inside of the article we do have an aside as well as some paragraphs and some headings and so forth. And what I would like to do is select only the paragraphs in the article, not the paragraphs in the aside. So I could write, start by writing some kind of selector like this, article p, color, red now that's going to select all of the paragraphs in the document, why is that? Well, look at the relationship that we have here, clearly this paragraph on line three is part of that article, but also the one here on line six, this is also descended from article. The parent of this paragraph is the aside, the parent of the aside is the article and so this style…

Contents