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 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
231,236 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.