Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to create horizontal menu with fixed width

Tags:

html

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?

like image 493
Thelambofgoat Avatar asked Mar 24 '23 12:03

Thelambofgoat


1 Answers

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/

like image 79
Ron van der Heijden Avatar answered Apr 02 '23 06:04

Ron van der Heijden