Using display: table to Create Full Width Navigations

Published Saturday, November 03, 2007 in (X)HTML, CSS, Semantics

Sometimes you need a navigation to span the entire width of its parent:

Full width navigation

Because all types of navigations are nothing but lists of links they should always be marked up with the unordered list element (ul) with each navigation-item in its own li-element.

A very common way to display the list of links horizontally is to float each li-element to the left which will make them all appear on one row, but the total width of a row of floated elements is determined by the elements' margin, padding, border and contents so you have no real control over the width of your navigation-bar (unless, of course, you set a fixed width to each li).

Using the CSS display-property together with its table, table-row and table-cell values you can make an unordered list behave like a table and easily make the navigation-items take up the full width of your site.

The following markup:

<div id="navigation">

    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Content</a></li>
    </ul>

</div>

And this CSS:

#navigation {
    display: table;
    width: 100%; /* tables are not 100% by default like block-level elements */
    border-spacing: 0;
    border-collapse: collapse:
}

    #navigation ul {
        display: table-row;
    }
    
        #navigation ul li {
            display: table-cell;
            border: 1px solid #000;
        }

Will do the trick. I've kept the styling as simple as possible, but to make your navigation a bit fancier you'll probably want to style the lis a little more.
Of course IE6 (dunno 'bout 7) doesn't support any of this but I've given up on that piece of shit ages ago, and I hope you have too. If everybody could just stop caring about IE people would eventually switch to a proper browser. I think we should encourage IE-users to switch and stop fixing things for that browser and it will happen sooner rather than later.


Rate It


Bookmark It

  • del.icio.us
  • Digg
  • Furl
  • Google
  • Technorati
  • Ma.gnolia
  • BlinkList
  • Blogmarks
  • Rojo
  • StumbleUpon


Post It

From June 02 to April 23

  1. Mogrify is what you're looking for if you want to convert multiple images to multiple other images in ImageMagick
  2. Tommorrow, finally, the inFamous demo will be friggin availble on PSN!! Suweeeeeeeeet
  3. Fuck canvas is cool, I've started playing around with old 3D-shit again :)

February 2012

S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29


Recent Comments

  1. buy thesis on A Modular Design Pattern:
    Choosing buy dissertation service a...
  2. research papers on A Modular Design Pattern:
    Want to find cheap literature essay...
  3. professional resume service on A Modular Design Pattern:
    Yeah doubtless very constructive f...
  4. website submission service on A Modular Design Pattern:
    Are willing to get Search engine op...

Style Switcher

The style switcher allows you to change the look and feel of exscale.se.
Only CSS and JavaScript are changed. The XHTML stays the same.

For more information about the styles, check the styles page.


Categories


Random Quote

T minus 10... 11 - The Dean


Random Images




Answer This!

Do you find the "scroll-pagination" annoying? (If you don't know what it is, scroll to the bottom of the first-page)


Blog Roll