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 trialJong Kim
6,145 Pointshow come margin-top: auto; makes item to the bottom? i just don't understand...
I just don't get it, Can anyone please explain with picture on it if possible? if not, how does it work like that?
2 Answers
Shung Chen
6,526 Pointson the teacher's note it said
A margin value of auto has an effect on flex item alignment because it absorbs any extra space around a flex item and pushes other flex items into different positions.
I guess, in other words, it means the "margin: auto" will eat up all the available space when push itself into the opposite direction in a flexbox environment.
e.g. if we put margin-top: auto, it will eat up all the available space on top of it and push the button to the bottom of that flexbox
Balaji Jangde
1,120 Pointsmargin-top:auto; is not gonna center your element vertically, margin-left:auto; and margin-right:auto; can be used to horizontally center the element but don't try it with vertical alignment
Jong Kim
6,145 Pointsmy concern is why margin-top: auto ; makes item to the bottom not into center (when display: flex;)