Pure CSS fisheye menu with icons

Yes, a pure CSS fisheye menu with icons can actually be done! First of all, we need a basic navigation menu, like this:

<ul id="navigation">
<li><a href="#" id="home">Home</a></li>
<li><a href="#" id="images">Images</a></li>
<li><a href="#" id="about">About</a></li>
<li><a href="#" id="contact">Contact</a></li>
</ul>

Each link has its own ID, because each item will have a different background image. We have two types of images here: small (28 x 28 pixels) and big (48 x 48 pixels), just to create the fisheye effect when an user moves his/her mouse over a link. Here's the CSS:

body {

    width: 60%;
    margin: 0 auto;
    padding: 2em 0;
    background: #fff;
    color: #333;
    font: 76% Arial, sans-serif;

}

#navigation {

    width: 100%;
    font-size: 1.1em; /* 1em = 13px */
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
    list-style: none;

}

#navigation li {

    float: left;
    height: 100%;
    margin-right: 4px;

}

#navigation li a {

    float: left;
    display: block;
    padding: 0 10px;
    font-size: 1.2em;
    color: #555;
    font-weight: bold;
    text-decoration: none;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: 50% 0;
    height: 100%;
    line-height: 5;
    

}

#navigation li a#home {

    background-image: url("img/home-small.jpg");

}

#navigation li a#home:hover {

    background-image: url("img/home-big.jpg");
    line-height: 7;

}

#navigation li a#images {

    background-image: url("img/images-small.jpg");

}

#navigation li a#images:hover {

    background-image: url("img/images-big.jpg");
    line-height: 7;

}

#navigation li a#about {

    background-image: url("img/about-small.jpg");

}

#navigation li a#about:hover {

    background-image: url("img/about-big.jpg");
    line-height: 7;

}

#navigation li a#contact {

    background-image: url("img/contact-small.jpg");

}

#navigation li a#contact:hover {

    background-image: url("img/contact-big.jpg");
    line-height: 7;

}

Each link has enough line-height, so that its text will be showed under the image. When you hover a link, the background image changes and the line-height increases to create a smooth animation effect. Each background image is horizontally centered within a link. You can see the final result here.

One thought on “Pure CSS fisheye menu with icons”

  1. Here's an alternate version looking to the future using CSS3 transition and transform:
    http://tjameswhite.com/demos/fisheye/

    It looks best in the webkit browsers as they have the smoothest transition, but it also works in Firefox and Opera.

Leave a Reply

Note: Only a member of this blog may post a comment.