+ Reply to Thread
Results 1 to 5 of 5

Basic dropdown menu using a little javascript

This is a discussion on Basic dropdown menu using a little javascript within the Web Design forums, part of the Web Designing & Development category; Code: [FONT=Arial Black][SIZE=2] <!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> <title>Horizontal Drop Down Menus</title> <meta http-equiv="Content-Type" ...

Share/Bookmark
  1. #1
    Senior Member Array akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    500

    Default Basic dropdown menu using a little javascript

    Code:
    [FONT=Arial Black][SIZE=2] <!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>
    <title>Horizontal Drop Down Menus</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!--[if lt IE 7]>
    <script type="text/javascript">
    sfHover = function() {
       var sfEls = document.getElementById("nav").getElementsByTagName("LI");
       for (var i=0; i<sfEls.length; i++) {
          sfEls[i].onmouseover=function() {
             this.className+=" over";
          }
          sfEls[i].onmouseout=function() {
             this.className=this.className.replace(new RegExp(" over\\b"), "");
          }
       }
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);
    </script>
    <![endif]-->
    
    <style type="text/css">
    body {
       font: x-small Verdana, Arial, Helvetica, sans-serif;
    }
    * html body{
       font-size:xx-small;
       f\ont-size:x-small;
    }
    ul#nav, ul#nav ul {
       margin: 0;
       padding: 0;
       list-style: none;
       }
    
    ul#nav  li {
       position: relative;
       float: left;
       width:149px;
    }
       
    #nav li ul {
       position: absolute;
       margin-left: -999em; /* hide menu from view */
       top: auto;
       left:0;
    }
    
    /* Styles for Menu Items */
    ul#nav  li a {
       display: block;
       text-decoration: none;
       color: #777;
       background: #ffffcc; /* IE6 Bug */
       padding: 5px;
       border: 1px solid #ccc;
          margin-bottom:-1px;
       min-height:0;
       }
    /* commented backslash mac hiding hack \*/
    * html ul#nav  li a {height:1%;   position:relative;}
    /* end hack */
    
    /* this sets all hovered lists to red */
    #nav li:hover a,#nav  li.over a,
    #nav li:hover li a:hover,#nav li.over li a:hover {
       color: #fff;
       background-color: red;}
    
    /* set dropdown to default */
    #nav li:hover li a,#nav li.over li a {
       color: #777;
       background-color: #ffffcc;
    }
    #nav li ul li a { padding: 2px 5px; } /* Sub Menu Styles */
    #nav li:hover ul,#nav li.over ul {margin-left:0; } /* show menu*/
    
    </style>
    </head>
    <body>
    <ul id="nav">
      <li><a href="#">Link 1</a></li>
      <li><a href="#">Link 2</a>
        <ul>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
        </ul>
      </li>
      <li><a href="#">Link 3</a>
        <ul>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
        </ul>
      </li>
      <li><a href="#">Longer Link 4</a>
        <ul>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
          <li><a href="#">Sub link</a></li>
        </ul>
      </li>
    </ul>
    
    </body>
    </html>[/SIZE][/FONT]

  2. #2
    Administrator Array SticKer's Avatar
    Join Date
    May 2007
    Posts
    3,641

    Default Re: Basic dropdown menu using a little javascript

    Thanks for sharing the code.

    SticKer

  3. #3
    Senior Member Array msn90's Avatar
    Join Date
    May 2009
    Location
    india
    Posts
    146

    Default Re: Basic dropdown menu using a little javascript

    This is very useful code. Thanks for sharing.

  4. #4
    Senior Member Array
    Join Date
    Jun 2009
    Posts
    192

    Default Re: Basic dropdown menu using a little javascript

    Thanks for sharing the code it is useful I will apply it in my site if needed.

  5. #5
    Junior Member Array
    Join Date
    Jul 2009
    Posts
    18

    Default Re: Basic dropdown menu using a little javascript

    I'd recommend using css instead, javascript tends to be slower than css drop down menus.

    here's a good tutorial on how to do it in css:

    www dot tjkdesign dot com/articles/dropdown/
    [COLOR="Blue"]In2net Network Inc.[/color] ( www.in2net.com ) : Providing Service Since 1996!
    Quick Sales Response - [color=black]info@in2net.com[/color]
    [COLOR="Blue"]Virtual Private Servers : VPS Hosting[/COLOR] - Ask us about our Managed Hosting services, too!
    30-Day MoneyBack Guarantee



+ Reply to Thread

Similar Threads

  1. menu using javascript?
    By abhilashdas in forum Programming
    Replies: 28
    Last Post: 04-28-2011, 08:42 PM
  2. Layer Menu
    By cyberbog in forum Web Design
    Replies: 1
    Last Post: 01-13-2009, 06:12 AM
  3. Web Development- Basic Things
    By akash in forum Web Design
    Replies: 0
    Last Post: 11-06-2008, 07:30 AM
  4. Replies: 1
    Last Post: 04-16-2008, 05:00 AM
  5. Replies: 0
    Last Post: 01-29-2008, 08:54 AM
SEO Forum | Web Hosting Forum | Websites For Sale |