# Center a container of floated elements

**URL:** <https://forum.kirupa.com/t/center-a-container-of-floated-elements/235140>\
**Category:** web dev\
**Created:** [August 8, 2007, 7:44pm UTC](https://forum.kirupa.com/t/center-a-container-of-floated-elements/235140 "2007-08-08T19:44:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Icy\_Penguin](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@Icy\_Penguin](https://forum.kirupa.com/u/Icy_Penguin)\
**Post date:** [August 8, 2007, 7:44pm UTC](https://forum.kirupa.com/t/center-a-container-of-floated-elements/235140/1 "2007-08-08T19:44:24Z")

</div>

Hey everyone,

I’m trying to center a horizontal navigation - so the \<li\>s are floated left. And I don’t define a width for them, just padding and such. So the \<ul\> and the \<div\> that it is in can’t have a width either ('cause it will always be changing, etc.).

Margin: 0px auto doesn’t work if a width is not defined on that element. How can I center the nav?
