Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Jordan C
Jordan C
6,249 Points

Can you use "margin-right: auto;" on the name in the header to make it so the name and nav are against opposite edges?

This would be instead of "justify-content: space-between;"

4 Answers

Steven Parker
Steven Parker
210,863 Points

When using flexbox, always try to do things the "flexbox way".

If there are only two items, then since "justify-content: space-between;" is intended to do exactly what you want, that would be the best-practice choice.

Using auto margins could be a good choice when you have multiple items to group together on opposite sides, but you may be able to achieve the same effect with combinations of "justify-content" on the container and "justify-self" on the items(s) to be aligned differently.

The interaction with auto-margins is one of the things the flexbox spec defines and it can be used to achieve interesting layouts, as shown in this answer on Stack Overflow.

By the way, the best article on flexboxes I've found so far is this one.

Thank you,
Nafis Fuad

I agree with Steven Parker.