scarhand Posted June 25, 2009 Share Posted June 25, 2009 heres my example: #theul { margin: 0px; padding: 0px; list-style-type: none; } #theul li { float: left; } #theul li a { display: block; } <ul id="theul"> <li><a href="#">horizontal menu item 1</a></li> <li><a href="#">horizontal menu item 1</a></li> <li><a href="#">horizontal menu item 1</a></li> </ul> How do I get this menu perfectly centered on the page, for a dynamic width? Link to comment https://forums.phpfreaks.com/topic/163701-centering-a-ul-with-floated-lis/ Share on other sites More sharing options...
jcombs_31 Posted June 25, 2009 Share Posted June 25, 2009 Just change the margin to margin: 0 auto; Link to comment https://forums.phpfreaks.com/topic/163701-centering-a-ul-with-floated-lis/#findComment-863798 Share on other sites More sharing options...
TheFilmGod Posted June 26, 2009 Share Posted June 26, 2009 Just change the margin to margin: 0 auto; That's incorrect. The ul does not have a fixed width, so the browser will stretch the width of the <ul> tag 100%. Centering a list that has floated items within itself is difficult. You could do "display: table" on the ul and then use "margin: 0 auto;" or you could just compute the pixel/em width of the ul tag by hand and put it directly in there. Link to comment https://forums.phpfreaks.com/topic/163701-centering-a-ul-with-floated-lis/#findComment-863847 Share on other sites More sharing options...
jcombs_31 Posted June 27, 2009 Share Posted June 27, 2009 It is still technically centered. If the list is supposed to stretch to 100% and the items are floated, it doesn't make sense not to just display them inline and center the text. What defines the 'dynamic width', the container? Link to comment https://forums.phpfreaks.com/topic/163701-centering-a-ul-with-floated-lis/#findComment-864714 Share on other sites More sharing options...
ifubad Posted July 5, 2009 Share Posted July 5, 2009 using display:table has problems with certain browsers, especially with some IE This is one of the better options for centering a floated list, personally, I prefer the first option on this page http://pmob.co.uk/pob/centred-float.htm Link to comment https://forums.phpfreaks.com/topic/163701-centering-a-ul-with-floated-lis/#findComment-869052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.