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

CSS Flexbox, can I have a parent inside the other parent?

If I have a <header> with two different divs. In the first <div>, there is an <h1> and a <p>. In the second <div>, there is an <ul> with 5 elements <li>. Is it possible to use the <li> elements as items for the parent container <ul> and at the same time, use the <ul> as an item for the parent <div>, and at the same use the 2 divs as items for the parent <header>. I'm not quite sure is it possible to use the Flexbox property as a Matrioska structure?

1 Answer

Steven Parker
Steven Parker
243,656 Points

Yes, a flex item can also be a flex container. Just give it the "display: flex" property along with any other flex container properties you need. All of its children then become flex items.

You can nest as much as you need, but be careful not to confuse yourself!