sseeley Posted March 21, 2009 Share Posted March 21, 2009 I am trying to create a CSS menu bar, I have been using the 'position:absolute;' and then specifying the x and y to place the object. However I really would like to just have the bar center on the webpage but I cannot find out how to do it. Can anyone help me at all? Many thanks in advance Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 21, 2009 Share Posted March 21, 2009 This should center your bar: <style> #menuBar { display: block; width: 50%; margin-left: auto; margin-right: auto; } </style> <body> <div id="menuBar">Your content here</div> Ken Quote Link to comment Share on other sites More sharing options...
sseeley Posted March 22, 2009 Author Share Posted March 22, 2009 Thanks Ken, did not work unfortuantly... Quote Link to comment Share on other sites More sharing options...
dbrimlow Posted March 22, 2009 Share Posted March 22, 2009 First, lose any "position:absolute" elements, they will not help you in the least. Next, you must specify a width in px or percentage or it doesn't work. For centering it is usually just "margin:0 auto". But you want 50px top margin so (I use 500px for example): <style> #menuBar { width: 500px; margin:50px auto 0 auto; } </style> <body> <div id="menuBar">Your content here</div> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.