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

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!