Search
Star
Feedback
Setup for Free
© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
why does margin-top auto only work if parent is a flex container - Kevin Powell - Community
KP-C
Kevin Powell - Community
•
2y ago
•
2 replies
snxxwyy
why does margin-top auto only work if parent is a flex container
Hey
, i made this example for someone and i
'm not quite sure the in depth reasoning as to why setting
margin-top: auto;
margin-top: auto;
on a child
(in this case
nav
nav
) doesn
't work unless the parent is a flex container
(in this case
.site-container
.site-container
)
, i just know it works and i
'd like to understand a little more
. I
'd appreciate any help
, thanks in advance
.
https://codepen.io/deerCabin/pen/OJeLPYW
CodePen
R
sticky-nav example
.
.
.
Kevin Powell - Community
Join
A friendly place for developers to meet other devs, ask questions, get help, and just have a good time 🙂.
36,263
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Similar Threads
How does margin-top: auto; work?
KP-C
Kevin Powell - Community / front-end
3y ago
margin-top: auto does not work inside a element
KP-C
Kevin Powell - Community / front-end
16mo ago
Why my margin does not work?
KP-C
Kevin Powell - Community / front-end
2y ago
Make grid container like having margin-top
KP-C
Kevin Powell - Community / front-end
17mo ago