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

Michał Nowak
Michał Nowak
2,809 Points

Position left/right

If I used .name{margin-right: auto;} is it correct method?

2 Answers

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

You can use the margin-right: auto css declaration which will absorb the extra space inside of a flex container and push any flex items that follow after the flex-item that has been assigned that css rule.

However, if you have two flex-items inside a flex-container which you want to separate by aligning one item to the left side of the flex-container and the other to the right side of the flex-container with space in between, you can achieve this by using justify-content: space-between on your flex-container.

Michał Nowak
Michał Nowak
2,809 Points

yes i know, but first method is worse than space between?

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

There is no worse methods. As long as you find a way to do something then it is a correct! There are no wrong ways of doing something, therefore, everybody will do things differently. The flexbox css property justify content maybe an approach more appropriate in this typical case because it has been made to minimize the use case of the margin calculations and to do it all in itself. That is the beauty of flexbox!