Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Scott Moore
Scott Moore
4,050 Points

Parent and child elements.

Just wondering. How often do you all use these when designing websites? They seem goofy, I'm just trying to picture in my mind when I would actually use something like this.

3 Answers

Laura Cressman
Laura Cressman
12,548 Points

I'm still pretty new to this, but I think that a parent element refers to any element that has descendants-that is, elements below it that are further indented. These further indented elements are called "children" if I remember correctly. If this is correct, then we actually use parent and child elements all of the time when designing websites. For example, if we have this code:

<ul class="nav">
  <li><a href="#">Home</a></li>
  <li><a href="#">About</a></li>
  <li><a href="#">Contact</a></li>

Then the ul element is the parent, with the list items (li) being children, which in turn are the parent elements of the anchor (a) tags. I think parent and children are just terms to describe this sort of relationship, not actual HTML elements with tags. The styling of parent elements (like the ul in this example) often impacts that of child elements (the list items and links). Does that make sense?

Dylan Grey Aksomitas
PLUS
Dylan Grey Aksomitas
Courses Plus Student 15,083 Points

You'll find yourself using them a lot once you start designing sites on a regular basis. I use them a lot to target nav list items and things like that. You definitely need to understand how they work. Having a good grasp on targeting parent child elements will also help you to understand nesting in Sass etc.

Scott Moore
Scott Moore
4,050 Points

Thanks for the replies. I do understand the parent child elements. I guess which will lead me into another question. Watching the video of the nth type stuff. Do those get used a lot? It seems like defining an ID or Class would be more useful and easier than diving into the nth. Looking at websites and checking the development tools. I don't think I have seen one website use the nth type. If anyone has a link to site which use the nth type would be great so I could see how it is applied.