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 Aligning Items to the Bottom of a Column

Jong Kim
Jong Kim
6,145 Points

how 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

on 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

margin-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
Jong Kim
6,145 Points

my concern is why margin-top: auto ; makes item to the bottom not into center (when display: flex;)