HTML Tutorial


 /help/HTML Help Forum   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Basic dropdown menu using a little javascript
Post new topic   Reply to topic    HTML Help Forum -> Member Tutorials
View previous topic :: View next topic  
Author Message
sticks464



Joined: 31 Dec 2006
Posts: 2631

PostPosted: Tue Dec 09, 2008 5:33 am     Basic dropdown menu using a little javascript Reply with quote

Code:
<!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>
sticks464



Joined: 31 Dec 2006
Posts: 2631

PostPosted: Tue Dec 16, 2008 11:22 am     Reply with quote

I've got some more of these posted in this section of the forums, don't run out of remarks just yet.
http://www.htmlcodetutorial.com/help/ftopic13353.html
http://www.htmlcodetutorial.com/help/ftopic13338.html
http://www.htmlcodetutorial.com/help/ftopic13337.html
http://www.htmlcodetutorial.com/help/ftopic13335.html
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum -> Member Tutorials All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial