Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • Wow that was fast, and like that hjsfiddle.net! But this is a fixed div 10/10 px from top left corner right? Not to the right in a centered parent div? Commented Feb 21, 2011 at 13:01
  • Yes, if you want it to stay fixed to the top of the screen, you have to use position: fixed;. With this you can't use margin centering, (margin: 0 auto;) so you can use the left property to place it as you like. You can use px, em, % or whichever unit you choose as your measurement. Commented Feb 21, 2011 at 13:11
  • And that is the question. I want the nav div in a position:fixed relative the parent div, not the browser window. Cant see how using em or % in css will get a correct behaviour if browser is resized. Would have to be some math involved then. Commented Feb 21, 2011 at 14:02
  • Aha, ok then, if the parent is position fixed, you can of course use margin: 0 auto ;) updated my answer with a new example :) Commented Feb 21, 2011 at 14:19
  • Parent is centered as in image above. Commented Feb 21, 2011 at 14:21