A Simple Menu Roll-over using jQuery and CSS

The following ASP.NET page shows a simple example of a menu created using a combination of CSS and jQuery.

The menu is defined as an unordered list (which makes semantic sense) and styled with CSS (a real web site would of course have its CSS defined in external file(s)). When the user moves the mouse over a menu item, a CSS class is dynamically added; then removed when the mouse leaves. In addition a simple "infobox" span is defined whose text is changed to that of the title attribute of the <a> element.

There are lots of examples of image based roll-overs, this one is really cool and based on a simple idea.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <script type="text/javascript" src="jquery-1.3.2.js"></script>

    <title>Simple jQuery Menu Example</title>

    <script type="text/javascript">

        var menuPrompt = "Please select a page to view."; // simple prompt for user
        $(document).ready(function() {

            // initialise the infobox prompt
            $(".nav_menu_list li a")
            .mouseover(function() {
                // add the mouseover style
                // set the text of the infobox span to the anchor title attribute
                $("#infobox").text("Go to " + $(this).attr("title"));
            .mouseout(function() {
                //remove the mouseover style
                // reset the text of the infobox span to user prompt

    <style type="text/css">
            list-style-type: none;
            margin: 0 0 0 21px;
            padding: 0;
        .nav_menu_list li
            float: left;
            text-align: left;
        .nav_menu_list li a
            display: block;
            padding: 0 10px 0 5px;
            text-decoration: none;
            font-size: 36pt;
            color: #0000FF;
            background-color: White;
            color: White;
            background-color: #ec1c24;
    <form id="form1" runat="server">
        <ul class="nav_menu_list">
            <li><a title="Page 1" href="#" class="nav_menu_item_notmouseover">Page 1</a> </li>
            <li><a title="Page 2" href="#" class="nav_menu_item_notmouseover">Page 2</a> </li>
            <li><a title="Page 3" href="#" class="nav_menu_item_notmouseover">Page 3</a> </li>
        <div style="clear: both;">
            <span id="infobox"></span>


Add comment