A Sleek Navigation Menu with CSS3

I’m in the middle of working on a new layout and design for Themes by bavotasan.com and I have been tossing around a few ideas for my main navigation menu. I don’t want anything too elaborate and I feel that jQuery would be better used elsewhere, so I decided to go with only CSS3. I plan on using rounded corners, a background gradient and a simple hover effect. All together it works quite nicely, but of course it only works on modern browsers that support CSS3 so IE users will be missing out once again.
First we need to put together a simple menu as an unordered list:


We’ll give our unordered list the ID main-navigation and our first list items the class first. You’ll see why in a second.
Next comes the CSS:

#main-navigation {
   width: 100%;
   -moz-border-radius: 8px;
   -khtml-border-radius: 8px;
   -webkit-border-radius: 8px;
   background: -webkit-gradient(linear, left top, left bottom, from(#444444), to(#666666));
   background: -moz-linear-gradient(top,  #444444,  #666666);
   filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#444444', endColorstr='#666666');
   border: 1px solid #444;
   list-style: none;
   padding: 0;
   margin: 0;
   float: left;
   }
#main-navigation li {
   float: left;
   border-right: 1px solid #777;
   }
#main-navigation li a {
   font: 13px Georgia, "Times New Roman", Times, serif;
   letter-spacing: 1px;
   padding: 12px 20px;
   border-right: 1px solid #333;
   display: block;
   color: #fff;
   }

The above CSS will give us a menu that looks like this:

A simple underline for the hover doesn’t quite cut it, so let’s add a cool hover effect:

#main-navigation li a:hover {
   background: -webkit-gradient(linear, left top, left bottom, from(#666666), to(#444444));
   background: -moz-linear-gradient(top,  #666666,  #444444);
   filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#666666', endColorstr='#444444');
   text-decoration: none;
}

Hover over a link below to see it in action.

All we did was reverse the gradient and it adds a cool effect. The only problem is that hovering over the first item gives us some strange squared corners. Fixing that requires some CSS styles for the list item with the classname first.

#main-navigation li.first a {
   -moz-border-radius: 8px 0 0 8px;
   -khtml-border-radius: 8px 0 0 8px;
   -webkit-border-radius: 8px 0 0 8px;
}

Now our final menu looks and functions exactly how we want it to.

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie