I am trying to create a navigation panel for my website. I would like it to consist of:
- Four tabs in equal size with text-centered in each tab.
- They should fill the whole page width.
I would really like the design to be flexible and browser friendly. I have tried various float techniques, but I can’t get it to work. I hope that you can help me out!
Thank you.
HTML
EDIT: it’s 2015 and HTML5 has been there for a while; following code should be inside a
navelement (html5doctor) with landmark ARIA attributerole="navigation"on it (and 99.9% of the time be unique in any given page).A navigation panel should use an unordered list of links:
CSS
EDIT2: It’s 2017, just use Flexbox (with or without
flex-wrap: wrap)inline-blockis useful but has one drawback: whitespace between two elements must be carefully managed. Whether removed or no</li>in HTML5 or</li>at the beginning of the following line stuck like</li><li>next itemor other tricks, you still have to do something or it’ll create a ~4px gap between 2 elements.25% + 25% + 25% + 25% doesn’t equal 100% on all browsers if the total isn’t a multiple of 4. Each browser has its own rounding method.
If you want elements to total 100% width and equal width, another method is to use
display: table(andtable-cell) withtable-layout: fixedto force browsers to use the other table algorithm, the one that doesn’t try to adapt cells width to content but respect the widths wanted by the designer/developer as far as possible.Fiddle
http://jsfiddle.net/PhilippeVay/aHCy3/1/
edit: http://jsfiddle.net/PhilippeVay/aHCy3/2/ with another method for space between each tab, courtesy of my colleague.