HAH, I found another way of handling it!!!
It uses a display property I am usually hesitant to resort to…
table and table-cell.
Naturally IE7- doesn’t like them, but IE handles display:inline just fine so we send it the word-spacing version… and I forgot that IE will collapse elements over each-other with word-spacing unless you set zoomfix. (zoom:1; – and in this case it’s NOT haslayout fixing it!).
I also hate using them because it ALWAYS feels like a cheat – if we want the behavior of a table why aren’t we just using a table… though the answer is that semantically this content probably isn’t a table.
table-cells normally don’t render white space between them – set the li to table-cell and the anchors to inline-block, and you’re close to what we want-- but for some screwy reason all browsers will put a cell-width of padding on the left you can’t control unless to set both table-layout:fixed and border-collapse:collapse; – of course then it’s narrow and we have to set margin:0 auto; – so you can’t render full width without another element - for testing I’m adding a DIV around it, in production I’d probably just use the background-image on the h1 above it (assuming we’re talking about a main menu).
SO:
First up, I made a markup guaranteed to make sure ANY formatting you can come up with is going to render the same way… No human being would write code like this
<div id="testMenu"><ul>
<li><a href="#">test</a></li><li><a href="#">test</a></li>
<li> <a href="#">test</a></li>
<li><a href="#"> test </a></li>
<li><a href="#">test</a> </li>
<li>
<a href="#">test</a>
</li><li>
<a href="#">test</a>
</li>
</ul></div>
All the different spacing types you could possibly have.
The UL gets:
#testMenu ul {
list-style:none;
margin:0 auto;
display:table;
table-layout:fixed;
border-collapse:collapse;
text-align:center;
word-spacing:-2em;
height:1%;
}
display:table to normalize the table-cell behavior and so we can set the fixed layout/collapsed borders. (both properties are ignored otherwise). We then set text-align:center and word-spacing for IE. Really wierd is that FF will often wrap table-cells almost at random when you refresh or hit a new page – this crops up from time to time and the fix is mindblowing…
The Holly Hack!!! The traditional IE haslayout trigger ALSO fixes quirky behavior in FF’s display:table.
The LI get:
#testMenu li {
display:table-cell;
display:inline !ie;
zoom:1;
}
NORMALLY we’d just set the display:inline first since IE doesn’t know table-cell and should be ignoring it… but IE is a total retard on the display property. I hate resorting to !IE, but it’s a quick and easy way to send this one property.
The anchors are just your normal inline-blocks
#testMenu a {
display:-moz-inline-block;
display:-moz-inline-box;
display:inline-block;
padding:8px;
white-space:nowrap;
word-spacing:0;
}
Inside table-cells the text will wrap funny even when there’s enough room for all the cells in FF and sometimes webkit. Adding the white-space:nowrap makes all the browsers behave the same way.
So putting that all together into a demo page:
http://battletech.hopto.org/html_tutorials/inlineMenu.html
We can see that it works – amazingly it works in FF 2 and 3, Opera 9.6+, the latest flavors of Safari and Chrome, and miracle of miracles even works back to IE 5.5.
No IE 5.0 though, it doesn’t know what inline-block is. (Like we give a flying Wallenda!)
So… another technique for pulling it off at least!