tags:

views:

1105

answers:

4

Hi,

So I have the following CSS in place to display a horizontal navigation bar using < ul >:

.navigation ul 
{
  list-style: none;
  padding: 0;
  margin: 0;
}

.navigation li
{
  float: left;
  margin: 0 1.15em;
  /*    margin: 0 auto;*/
}

.navigation 
{
  /*    width: auto;*/
  /*    margin: 0 auto;*/
  text-align: center;
}

It currently looks like this: http://www.grabup.com/uploads/129643f03898eea2d1b60a9db87c1e60.png.

My question is: how do I align the navigation bar centrally above the title?

Thanks

+4  A: 

Give your .navigation ul a width and use margin:0 auto;

.navigation ul 
{
  list-style: none;
  padding: 0;
  width: 400px;
  margin: 0 auto;
}
Emily
A: 

You could set the <li>'s to be display: inline, then set text-align: center on the <ul>. Doing that, you can remove the float: left from the list items and you don't need to have a fixed width for the navigation bar as you would if you used margin: 0 auto.

<html>
  <head>
    <style>
      ul { 
        list-style: none;
        text-align: center;
      }

      li {
        display: inline;
        margin: 0 1.15em;
      }
    </style>
  </head>

  <body>
    <ul>
      <li>Option 1</li>
      <li>Option 2</li>
      <li>Option 3</li>
    </ul>
  </body>
</html>
John Kugelman
+2  A: 

Well, to use margin:0 auto on something, it must have a defined width. Probably the best workaround is:

ul li {
  display: inline;
  list-style-type: none;
}
ul {
  text-align:center;
}
Fat Lotus