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 Link to comment https://forums.phpfreaks.com/topic/150499-css-center/ 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 Link to comment https://forums.phpfreaks.com/topic/150499-css-center/#findComment-790464 Share on other sites More sharing options...
sseeley Posted March 22, 2009 Author Share Posted March 22, 2009 Thanks Ken, did not work unfortuantly... Link to comment https://forums.phpfreaks.com/topic/150499-css-center/#findComment-790858 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> Link to comment https://forums.phpfreaks.com/topic/150499-css-center/#findComment-790887 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.