Page Widget How to - Create Simple Horizontal Nav with CSS








Question

We would like to know how to create Simple Horizontal Nav with CSS.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
ul {<!--from   w w  w.  j ava2  s. com-->
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  float: left;
}

li+li {
  border-left: 1px solid #ccc;
}

a {
  display: block;
  padding: 7px 10px;
  color: #222;
  background: #eee;
  text-decoration: none;
}

a:hover {
  color: #fff;
  background: #666;
}

a:active {
  color: #fff;
  background: #0090cf;
}
</style>
</head>
<body>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</body>
</html>

The code above is rendered as follows: