Style Sheets
  Home arrow Style Sheets arrow Page 4 - Fixing Browser Incompatibilities in 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

Fixing Browser Incompatibilities in a CSS Drop-Down Menu
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-10-22

    Table of Contents:
  • Fixing Browser Incompatibilities in a CSS Drop-Down Menu
  • Review: the initial source code for the CSS-based drop-down menu
  • Fixing browser incompatibilities
  • Adding JavaScript to correct browser incompatibilities
  • The modified version of the CSS-based drop-down menu

  • 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


    Fixing Browser Incompatibilities in a CSS Drop-Down Menu - Adding JavaScript to correct browser incompatibilities


    (Page 4 of 5 )

    As you'll surely recall from the prior section, this drop-down menu required the assistance of a JavaScript function to make it work properly in Internet Explorer, because of IE's lack of support for the "hover" CSS pseudo class.

    With that concept in mind, below I defined a brand new function. It is called "initializeDropDownMenu()" and it activates/deactivates the "over" class that I created previously for all of the menu items. It turns the menu in question into a truly cross-browser piece of software.

    The mentioned JavaScript function looks like this:


    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();

    }

    }


    As you can see, the previous "initializeDropDownMenu()" function is tasked with enabling/disabling the "over" CSS class attached to all of the menu items. In doing this, I'm actually emulating native support for the "hover" CSS pseudo class in <li> elements, which makes the menu work as expected with Internet Explorer. Quite simple, isn't it?

    Well, at this point I've introduced all the changes required to get this drop-down menu working with most modern browsers. So the last step that needs to be taken is simply putting all the pieces together, so you can see more clearly how they link with each other.

    Thus, to see the complete source code that corresponds to this menu, please jump ahead and read the final section of this tutorial. We're almost done!

    More Style Sheets Articles
    More By Alejandro Gervasio


       · In this second chapter of the series, support for the CSS hover pseudo class is...
       · I really enjoyed your article, and plan on using it in future website designs. The...
       · Thanks Alicia for the words on my article. Of course that specific CSS classes...
     

    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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek