Voglio un drop down menu senza javascript!!

…se questa è la vostra richiesta, eccovi accontentati.

Ci pensa Pixelspread a darci la “pappa pronta” e segnalarci come farlo grazie ad un suo esempio. Ovviamente non funziona su ie6

After playing with some javascript menus today, I decided to see if I could pull off a drop down menu without any javascript. I’ve seen it done before, so I thought I’d give it a shot. It actually ended up being pretty simple, so I thought I’d share the how-to.

I uploaded a demo of what I mean. If you take a look at the source, the basic elements of the menu are ul and li tags.

The first thing to do is differentiate the parent menu items from the menu items that only appear after you hover over the parent item. I did this with classes.

You’ll see the parent item is marked with top, while the rest are marked item. Now I can get to hiding .item and letting .top continue to show. So I’ll add this to the style sheet.

#menu ul .item{display:none;}

And when I hover over the top of the unordered list, I want all list items with class item to appear again. Here’s what I’ll add to the style sheet.

#menu ul:hover .item{display:block;}

You could choose to use display:block or display:inline. The last important piece is the position of the menu.

#menu{position:absolute;}

I wouldn’t say this is necessary, but if you’d like the drop down to appear on top of the content below, it is. Otherwise, your CSS menu will just displace everything underneath it.

You can dig through more of the source from the demo if you’d like to see the styling of the menu. Most important of all, this is all web standards compliant, and keeps the HTML of the page beautiful. I’ve tested it successfully in Camino 1.5.1, Firefox 2.0.0.9, and Safari 3.0.3. If you’d like test it anywhere and see how it fairs, go for it.

Leave a Reply

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Iscriviti alla newsletter

…se vuoi ricevere qualche consiglio su come spingere la tua attività sul web

Lauryn è un progetto che esiste dal 2001 ed è ideato da Laura Gargiulo, web designer ed esperta di web marketing.

Chi sono

About Us

Contact Us

Products

Services

Blog

Features

Analytics

Engagement

Builder

Publisher

Help

Privacy Policy

Terms

Conditions

Product

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
You have been successfully Subscribed! Ops! Something went wrong, please try again.

Laura Gargiulo | professionista ai sensi della Legge 4/2013 | Via Arrigo Minerbi 3, 20142 Milano – PI IT10339790965‬ |
Tutti i diritti riservati© 2025 Created with Royal Elementor Addons

Torna in alto