CSS CSS Flexbox Layout Building a Layout with Flexbox Aligning Items to the Bottom of a Column

Jasper Kop
Jasper Kop
9,057 Points

why is the auto top margin moving the button down?

I wonder why the auto top margin is moving the button down?

when I was thinking about the question van Gail I had some idea's but after trying them it didn't work out of course, but I don't understand the auto top margin why it works

2 Answers

Hi 2pd, The key to your question is that the item, in this case the button, needs to be a (flex item), then when you apply margin-top: auto; to your button it will take up all the (space available) around itself therefore pushing the item to the bottom of the box, just like you would use margin-left: auto; and margin-right: auto; it centers the item, but if you take away margin-left: auto; the item will move all the way to the left of the container it's in, I recommend watching the video again, also try using the code in different scenarios to understand it better.

Happy coding, Cheers!

Carlos Saborio
Carlos Saborio
5,387 Points

Thanks for the answer Jim!

Samet Erpik
Samet Erpik
1,187 Points

You can set the margin property to auto to horizontally center the element within its container.

2pd
2pd
6,719 Points

How does your comment explain why the buttons move to the bottom of the container?