tags:

views:

38

answers:

3

Pseudo HTML

<div>
 <ul>
  <li>Nav 1</li>
  <li>Nav 2</li>
 </ul>
</div>

I want this to look like

[DIV---------------[UL nav1 nav2]----------------------]

Instead I get

[DIV[UL nav1 nav2-----------padding-------------------]]

The li's are left floated. The ul has overflow: auto. How can I get the ul to be as wide as it needs to be, not as wide as it can be, so I center it with an auto margin?

+1  A: 

Try:

div { text-align: center; }
ul { display: inline; }

You may also want to try adding:

li { display: inline; }
cletus
I also need to set a height for it, so it must be a block. I am currently using inline-block in the live version, but that is unsupported by IE7
Bart van Heukelom
Found a way to have IE7 mimic inline-block, which is setting display: inline and zoom: 1
Bart van Heukelom
+1  A: 

In that case set the height on the div AND li's but make them inline, like Mr cletus says.

Or give up and use a <table>, although that'll get the css police banging on your door at 3am.

In the old days, we just used <table> and <img> and didn't know it was wrong. Like smoking in the 1970s, or listening to Rick Astley in the 1980's. We all did it, and still do once in a while when we think nobody is running us through a validator.

Christopher Gutteridge
inline elements don't allow the setting of height
Bart van Heukelom
A: 

Using display: inline-block with IE hack:

zoom: 1;
display: inline;
Bart van Heukelom