Home arrow Style Sheets arrow Page 3 - Fixing Browser Incompatibilities in a CSS Drop-Down Menu
STYLE SHEETS

Fixing Browser Incompatibilities in a CSS Drop-Down Menu


Drop-down menus have long been an important part of numerous web-based user interfaces. Since they have been around so long, we've seen many different approaches to building them, from pure JavaScript-driven menus, Flash-based ones, and simple, well-structured (X)HTML markup. This three-article series shows you how to build a drop-down menu using only clean and tight structural markup, along with a few simple CSS styles and a bit of JavaScript code.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 2
October 22, 2008
TABLE OF CONTENTS:
  1. · Fixing Browser Incompatibilities in a CSS Drop-Down Menu
  2. · Review: the initial source code for the CSS-based drop-down menu
  3. · Fixing browser incompatibilities
  4. · Adding JavaScript to correct browser incompatibilities
  5. · The modified version of the CSS-based drop-down menu

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Fixing Browser Incompatibilities in a CSS Drop-Down Menu - Fixing browser incompatibilities
(Page 3 of 5 )

As I expressed in the previous section, this CSS-based drop-down menu needs the assistance of JavaScript to work with Internet Explorer, in this way solving this relevant incompatibility issue.

Nevertheless, before coding any JavaScript snippets, I'm going to modify the original set of CSS styles that corresponds to the menu, so each of its items can be easily targeted via client-side scripting to hide and show them alternatively.

If the previous explanation sounds rather confusing to you at first, please have a look at the following CSS styles. They have been slightly changed to make the menu's items suitable for being manipulated via JavaScript.

Here's how the aforementioned CSS styles now look:


/* 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{

float: left;

position: relative;

width: 10em;

}

/* position and hide drop-down menu */

li ul{

display: none;

position: absolute;

top: 1em;

left: 0;

}

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;

}


As you can see, the most significant change I introduced in the above CSS styles consists of adding an "over" class to all of the menu items. This will allow them to be hidden or displayed when the mouse is over its respective top-level element by the means of a simple JavaScript function.

Naturally, this modification would be completely unnecessary if Internet Explorer offered decent support for the "hover" CSS pseudo class, but for the moment you'll have to settle for things being just the way they are.

All right, now it's time to define a simple JavaScript function that will hide/display the corresponding menu items in Internet Explorer (obviously, this isn't required for most non-IE based browsers), so if you want to see how this function will look, please click on the link below and keep reading.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials