Style Sheets
  Home arrow Style Sheets arrow Page 4 - Improving the Visual Presentation of a CSS...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Improving the Visual Presentation of a CSS Drop-Down Menu
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2008-10-29

    Table of Contents:
  • Improving the Visual Presentation of a CSS Drop-Down Menu
  • A review: the menu’s complete source code
  • Improving the look and feel with additional CSS styles
  • Setting up a working example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Improving the Visual Presentation of a CSS Drop-Down Menu - Setting up a working example


    (Page 4 of 4 )

    As I expressed in the section that you just read, the best way to grasp the logic that drives this highly accessible drop-down menu consists of listing its complete source code. In doing so, you’ll have a much better idea of how it works, and eventually, how it can be improved.

    Having said that, here’s the complete definition for the menu in question:


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Example of CSS-based drop-down menu (cross-browser compatible)</title>

    <style type="text/css">

    /* reset body styles */

    body{

    padding: 0;

    margin: 0;

    background: #fff;

    }

    /* style unordered list */

    ul{

    padding: 0;

    margin: 0;

    list-style: none;

    }

    /* style menu items */

    li.topitem{

    float: left;

    position: relative;

    width: 15em;

    padding: 5px;

    background: #fc0;

    font: bold 11px Tahoma, Arial, Helvetica, sans-serif;

    color: #000;

    }

    /* position and hide drop-down menu */

    li.topitem ul{

    display: none;

    position: absolute;

    top: 22px;

    left: 0;

    background: #ffc;

    padding: 5px;

    }

    li > ul{

    top: auto;

    left: auto;

    }

    /* display drop-down menu (add an 'over' class attribute to list items for IE */

    li:hover ul,li.over ul{

    display: block;

    }

    #navbar li li a {

    font: normal 11px Verdana, Arial, Helvetica, sans-serif;

    color: #000;

    padding: 5px;

    text-decoration: none;

    }

    #navbar li li a:hover {

    color: #00f;

    }

    </style>

    <script language="javascript">

    function initializeDropDownMenu(){

    // get 'navbar' element

    var navbar=document.getElementById('navbar');

    if(!navbar){return};

    // get all menu items

    var menuitems=navbar.getElementsByTagName('li');

    if(!menuitems){return};

    for(var i=0;i<menuitems.length;i++){

    // assign 'over' class attribute to each menu item on 'mouseover'

    menuitems[i].onmouseover=function(){

    this.className+=' over';

    }

    // remove 'over' class attribute to each menu item on 'mouseout'

    menuitems[i].onmouseout=function(){

    this.className=this.className.replace(' over','');

    }

    }

    }

    // initialize drop-down menu when web page is loaded

    window.onload=function(){

    if(document.all&&document.getElementById&&document.getElementsByTagName){

    initializeDropDownMenu();

    }

    }

    </script>

    </head>

    <body>

    <ul id="navbar">

    <li class="topitem">About Us

    <ul>

    <li><a href="">Our Staff</a></li>

    <li><a href="">Why work with us?</a></li>

    <li><a href="">Our profile</a></li>

    <li><a href="">More details</a></li>

    </ul>

    </li>

    <li class="topitem">Services

    <ul>

    <li><a href="">Graphic Design</a></li>

    <li><a href="">Web Design</a></li>

    <li><a href="">Web Programming</a></li>

    <li><a href="">Software Development</a></li>

    </ul>

    </li>

    <li class="topitem">Products

    <ul>

    <li><a href="">Simple AJAX Library</a></li>

    <li><a href="">PHP Form Validator</a></li>

    <li><a href="">PHP MySQL Connector</a></li>

    <li><a href="">PHP Easy Pager</a></li>

    <li><a href="">PHP Form Factory</a></li>

    </ul>

    </li>

    </ul>

    </body>

    </html>


    In addition, if the previous source code isn’t simple enough to demonstrate how this menu functions, you may want to download here (link) all of its supporting material, so you can test it with your own browsers.

    Final thoughts

    Sadly, this is the end of the series. But this isn’t necessarily bad, since hopefully you’re now equipped with the required background to build highly accessible drop-down menus by using the proper combination of well-structured markup, CSS styles and JavaScript.

    See you in the next tutorial on web development!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In this final chapter of the series, a few additional CSS styles are added to the...
       · Thanks for the article, but the link you provide at the end for teh zip file is...
       · Thanks for the kind comments. Hopefully the link will be fixed up soon. Sorry about...
       · Forgot the "p" in the last complete, it should...
       · Try...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek