Page Widget How to - Align menu to the center








Question

We would like to know how to align menu to the center.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div.horizontal {<!--from  w  ww  . j a  v  a 2 s . c o m-->
  width: 700px;
  height: 30px;
  margin: 0 auto;
}

div.horizontal ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

div.horizontal li {
  float: left;
  width: 100px
}

div.horizontal a {
  display: block;
  position: relative;
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 18px;
  padding-bottom: 0px;
}

div.horizontal a:link, div.horizontal a:visited {
  white-space: nowrap;
  height: 40px;
  line-height: 15px;
  font-weight: normal;
  font-size: 12px;
  overflow: hidden;
  text-decoration: none;
  text-transform: uppercase;
  z-index: 100;
  color: #fff;
  cursor: pointer;
  background-color: red;
}

div.horizontal a:hover, div.horizontal a:active {
  background-color: blue;
  color: #FFF;
}
</style>
</head>
<body>
  <div class="horizontal">
    <ul>
      <li><a href="">about us</a></li>
      <li><a href="">comments</a></li>
      <li><a href="">media center</a></li>
      <li><a href="">news</a></li>
      <li><a style="border-right: 2px #900 solid;" href="">contacts</a></li>
    </ul>
  </div>
</body>
</html>

The code above is rendered as follows: