I wonder, what's the best way to create horizontal menu with fixed width and variable number of items?
To adjust menu to make items equally spaced on menu strip, seems the only way is to use table width=100%
as menu wrapper and items as td
. So they would be adjusted automatically.
Is there another solution (without td
), considering that we don't know the number of items and, moreover, it can vary?
You could give the <ul>
/<ol>
a display: table
and the <li>
a display: table-cell
:
HTML:
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
CSS:
ul {
width: 100%;
margin: 0;
padding: 0;
display: table;
}
li {
display: table-cell;
text-align: center;
}
http://jsfiddle.net/8RXUw/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With