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
Jamie Reardon
Front End Web Development Techdegree Student 12,522 Points

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
Jamie Reardon
Front End Web Development Techdegree Student 12,522 Points

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!