CSS CSS Flexbox Layout Building a Layout with Flexbox Building a Navigation Bar with Flexbox

Tyler Halstead
Tyler Halstead
7,987 Points

Why do you have to target individual classes when using the display property, but not the align-items property?

It seems like in order to display main-header and main-nav as flex, they both have to be directly targeted in CSS, yet if you wanted to center align the list in main-nav, you can just target .main-header and use align-items. Are the 2 properties treated differently in some way?

Please post your markdown.

1 Answer

Liam Clarke
Liam Clarke
Treehouse Moderator 19,841 Points

Hi Tyler

I think your talking about the relation between parent (container) and children (items) in flexbox.

Flexbox uses the relationship between the two to create the layout. As above you mentioned adding display flex to the container will define the element as a flexbox container. Adding align items center is now talking about all direct children to that container.

so if main-header is defined as a flex container and the direct children is the main-nav then using the align-items property will target all direct children on the main-header.

You can check out more of the terminology and behaviour here