PDA

View Full Version : Dropdown menu with css and javascript...?



AllanH
13 May 2009, 05:50 AM
Hi, im having trouble with a dropdown menu im trying to get working properly. Im using notepad++ for editing, but not sure thats the problem. My problem is that im not that good at coding, but have to create this menu for a project. Therefor I hope theres someone in here, with the knowledge and time to help me out, so the foldout or expanding of the menu will work. Theres a file with the javascript and one with the css code and i have put them below this.

File with javascript:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>JavaScript Dropdown Menu</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<ul class="menu" id="menu">
<li>
<a href="#" class="menulink">Dropdown Menu 1</a>
<ul>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 1</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 2</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 3</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 4</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 5</a></li>
</ul>
</li>
<li>
<a href="#" class="menulink">Dropdown Menu 2</a>
<ul>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 1</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 2</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 3</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 4</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 5</a></li>
</ul>
</li>
<li>
<a href="#" class="menulink">Dropdown Menu 3</a>
<ul>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 1</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 2</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 3</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 4</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 5</a></li>
</ul>
</li>
<li>
<a href="#" class="menulink">Dropdown Menu 4</a>
<ul>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 1</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 2</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 3</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 4</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 5</a></li>
</ul>
</li>
<li>
<a href="#" class="menulink">Dropdown Menu 5</a>
<ul>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 1</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 2</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 3</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 4</a></li>
<li><a href="http://www.google.com" class="sub">Dropdown Menu 5</a></li>
</ul>
<div id="text" style="float:left; clear:left; width:650px; margin-top:10px">
</div>
<script type="text/javascript">
var menu=new menu.dd("menu");
menu.init("menu","menuhover");
</script>
</body>
</html>



-----------

File with CSS code:

body {margin:25px; font:11px Verdana,Arial; background:#eee}
ul.menu {list-style:none; margin:0; padding:0}
ul.menu * {margin:0; padding:0}
ul.menu a {display:block; color:#000; text-decoration:none}
ul.menu li {position:relative; float:left; margin-right:2px}
ul.menu ul {position:absolute; top:26px; left:0; background:#d1d1d1; display:none; opacity:0; list-style:none}
ul.menu ul li {position:relative; border:1px solid #aaa; border-top:none; width:148px; margin:0}
ul.menu ul li a {display:block; padding:3px 7px 5px; background-color:#d1d1d1}
ul.menu ul li a:hover {background-color:#c5c5c5}
ul.menu ul ul {left:148px; top:-1px}
ul.menu .menulink {border:1px solid #aaa; padding:5px 7px 7px; font-weight:bold; background:url(images/header.gif); width:134px}
ul.menu .menulink:hover, ul.menu .menuhover {background:url(images/header_over.gif)}
ul.menu .sub {background:#d1d1d1 url(images/arrow.gif) 136px 8px no-repeat}
ul.menu .topline {border-top:1px solid #aaa}

mindfullsilence
14 May 2009, 03:59 AM
hmm....I actually just did this with the site I'm working on. Mind posting your script.js file?