Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evenly spread links over a horizontal navigation

Tags:

html

css

I'm trying to find a simple method of getting all the links spread evenly over the horizontal navigation. This would be very easy if it would be a fixed amount of links, but they will be dynamic.

So it could be either 5 or 10 links, nobody knows. Despite the amount of links I would like them to spread evenly across the navigation without using a table.

The reason I don't want to use a table is because it will break the UL LI structure which is (apparently) considered the way to go when building a navigation (SEO).

Here's a jsFiddle explaining it more in depth: http://jsfiddle.net/pkK8C/19/

Looking for the most light method.

Thank you in advance.

like image 612
Rick Kuipers Avatar asked Feb 20 '12 23:02

Rick Kuipers


People also ask

How can I make my navbar full width?

The simplest way to get the effect you are looking for (for any number of buttons) is to use a table with a 100% width. A more complicated way is to give each button an equal percentage width such that with the number of buttons it adds up to 100%. You have 5 buttons, so you can put width:20%; on #nav ul li .


2 Answers

Use display: table for UL and display: table-cell for LI. And display-table.htc for IE6/7 if they matter.

like image 142
Marat Tanalin Avatar answered Sep 21 '22 23:09

Marat Tanalin


Old browser might be a headache, but it works for new ones:

div#navigation ul {
    list-style-type:none;
    height:30px;
    text-align:center;
    width: 100%;      /* new */
    display: table;   /* updated */
}

div#navigation ul li {        
    margin-left:50px;
    display: table-cell;  /* updated */  
}
like image 21
Dmitry Nogin Avatar answered Sep 19 '22 23:09

Dmitry Nogin