Using auto margins to center vertically | #shorts
דרג סרטון זה
התחבר כדי לדרג
תיאור
Code: https://codepen.io/kevinpowell/pen/povpeoK
While we can vertically center items with align-items: center on the parent, or align-self: center; on the child, this only works if the flex-direction is row. If we change that to column, it's no longer vertically centered.
One of the nice things with flexbox (and grid!) is that margin-top: auto and margin-bottom: auto work like left and right, so we can use that to center things vertically regardless of the flex-direction.
#css
--
Come hang out with other dev's in my Discord Community
💬 https://discord.gg/nTYCvrK
Keep up to date with everything I'm up to
✉ https://www.kevinpowell.co/newsletter
Come hang out with me live every Monday on Twitch!
📺 https://www.twitch.tv/kevinpowellcss
---
Help support my channel
👨🎓 Get a course: https://www.kevinpowell.co/courses
👕 Buy a shirt: https://teespring.com/stores/making-the-internet-awe...
💖 Support me on Patreon: https://www.patreon.com/kevinpowell
---
My editor: VS Code - https://code.visualstudio.com/
---
I'm on some other places on the internet too!
If you'd like a behind the scenes and previews of what's coming up on my YouTube channel, make sure to follow me on Instagram and Twitter.
Twitter: https://twitter.com/KevinJPowell
Codepen: https://codepen.io/kevinpowell/
Github: https://github.com/kevin-powell
---
And whatever you do, don't forget to keep on making your corner of the internet just a little bit more awesome!