Click to See Complete Forum and Search --> : 2 different menu types on the same page possible?


dang
08-05-2006, 11:03 AM
Hello all,

New guy here, looking for help. :)

First off I'm fairly new to using CSS except for basic text formatting and other easy stuff, but I'm a fast learner. And I have tried searching but couldn't find an answer.

The problem is the company I'm doing a site for would like to combine two different types of list based menus on the same page, a vertical expanding drop-down on top and a flyout menu below that. I've looked around and found the correct codes for each type of menu. Each one on their own works fine. But when I try to use them on the same page, they either don't work, only one type works and the formatting is messed up.

The code for each menu is very similar and they use the same javascript function (for IE I've learned). I've tried some things, changing the name of each list in the <ul> tag and in the javascript ( getElementById("nav"); ) and the name of the javascript function. But beyond that I don't know what to do or if it's even possible to have these on the same page.

The code I'm using I got from this site:
http://www.pmob.co.uk/

for the expanding drop-down:
http://www.pmob.co.uk/temp/dropdown-vert2.htm

and for the flyout menu
http://www.pmob.co.uk/temp/dropdown-vertical3.htm

So, is what I'd like to do possible? Is it a hard fix? ;)

Thanks.

ewallace
08-05-2006, 11:57 AM
This is a stab, but you could get the drop down effect with just CSS and no javascript at all. Maybe if you did one menu that way they would step on each others toes?

Sorry, not much of an expert on javascript, but that was the first ides that came to mind. I'm sure there will be someone else with much more expertise.
-E

dang
08-05-2006, 07:06 PM
Thanks for the reply.

I actually did try some other javascript/css soultions for the menus but with the same results. I haven't found a css only soultion for the drop down. Do you know of one you could point out to me that I could try?

Any one else have any thoughts on my problem?

Thanks.

Kor
08-06-2006, 07:27 AM
1. a CSS dropdown or tree like menu is possible only in Mozilla.
2. usually menu javascript codes use window.onload event to fire a start function. This event must be unique on page, so that you should use only a single onload, placed nomatter where, which should trigger both starting menu functions

window.onload=function(){
startmenu1func();
startmenu2func();
}

That is requred whenever you have more than a single code which needs onload event to start.

dang
08-06-2006, 11:56 AM
Thanks! That helped some. It's not as messed up as before, but there's still the problem of the formatting. I'm guessing it has something to do with the <ul> <li> tags because now both the expanding and flyout menus look the same. They both look like how the flyout is supposed to look with the exception of the border around the flyout menu.

I've included the code here now, maybe that'll help clear up what I'm clumsily trying to say. I've changed things a bit to make it easier to differentiate between the two menus. The top expanding menu should have a yellow background which changes to a red backgound on rollover. The bottom flyout menu should have a green background with a blue background on rollover. If you take a look both menus still have a green background and both menus flyout on rollover.

If someone could kindly help me on how to make the two menus look and behave as they should, that would be so great!

<!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>Vertical Drop Down Menus</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
// JavaScript Document

startList1 = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("topnav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}

startList2 = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}

window.onload=function() {
startList1();
startList2();
}
</script>

<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:x-small;
}
* html body{
font-size:xx-small;
f\ont-size:x-small;
}

/*---TOP EXPANDING MENU--*/
ul {
margin: 0;
padding: 0;
list-style: none;
width:150px
}

ul li {
position: relative;
width:148px;
border: 1px solid #ccc;
}
/* keep folowing styles together..........................*/
* html ul ul {
margin-left:-16px;/* ie5 fix */
voice-family: "\"}\"";
voice-family: inherit;
}
* html ul li {float:left;/* hide float from ie5*/}
* html ul ul {
width:148px;
voice-family: "\"}\"";
voice-family: inherit;
}
* html ul ul {margin-left:0;/* hide margin from ie5*/}

/* keep above styles together .............*/

li ul {
display:none;
background:#ffffcc
}
li ul li{border:none;}
/* Styles for Menu Items */
ul li a {
display:block;
text-decoration: none;
color: #777;
background: #ffffcc ;
line-height:2em;
height:2em;
padding:0 5px
}
/* this sets all hovered lists to red */
li:hover a, li.over a,
li:hover li a:hover, li.over li a:hover {
color: #fff;
background-color: red;
}

/* set dropdown to default */
li:hover li a, li.over li a {
color: #777;
background-color: #fff;
}
li ul li a { } /* Sub Menu Styles */
li:hover ul, li.over ul { display:block } /* The magic */

/*--BOTTOM FLYOUT MENU--*/

ul {
margin: 0;
padding: 0;
list-style: none;
width:150px
}

ul li {
position: relative;
width:148px;
border: 1px solid #ccc;
}
/* keep folowing styles together..........................*/
* html ul ul {
margin-left:-16px;/* ie5 fix */
voice-family: "\"}\"";
voice-family: inherit;
}
* html ul li {float:left;/* hide float from ie5*/}
* html ul ul {
width:150px;
w\idth:148px;
voice-family: "\"}\"";
voice-family: inherit;
}
* html ul ul {margin-left:0;/* hide margin from ie5*/}

/* keep above styles together .............*/

li ul {
position: absolute;
top: 0;
left:-999em;
}
/* Styles for Menu Items */
ul li a {
display:block;
text-decoration: none;
color: #777;
background: #99cc66; /* IE6 Bug */
line-height:2em;
height:2em;
padding:0 5px
}

/* this sets all hovered lists to blue */
li:hover a, li.over a,
li:hover li a:hover, li.over li a:hover {
color: #fff;
background-color: blue;
}

/* set dropdown to default */
li:hover li a, li.over li a {
color: #777;
background-color: #fff;
}
li ul li a { } /* Sub Menu Styles */
li:hover ul, li.over ul { left:149px; } /* The magic */

</style>
</head>

<body>
<table>
<tr><td>
<!--TOP EXPANDING MENU-->
<ul id="topnav">
<li><a href="#">Expanding Menu </a></li>
<li><a href="#">About &darr; </a>
<ul>
<li><a href="#">History </a></li>
<li><a href="#">Team </a></li>
<li><a href="#">Offices </a></li>
</ul>
</li>
<li><a href="#">Services&darr; </a>
<ul>
<li><a href="#">Web Design </a></li>
<li><a href="#">Internet Marketing </a></li>
<li><a href="#">Hosting </a></li>
<li><a href="#">Domain Names </a></li>
<li><a href="#">Broadband </a></li>
</ul>
</li>
<li><a href="#">Contact Us&darr; </a>
<ul>
<li><a href="#">United Kingdom</a></li>
<li><a href="#">France</a></li>
<li><a href="#">USA</a></li>
<li><a href="#">Australia</a></li>
</ul>
</li>
</ul>
<!--BOTTOM FLYOUT MENU-->
<ul id="nav">
<li><a href="#">Flyout Menu </a></li>
<li><a href="#">About </a>
<ul>
<li><a href="#">History </a></li>
<li><a href="#">Team </a></li>
<li><a href="#">Offices </a></li>
</ul>
</li>
<li><a href="#">Services </a>
<ul>
<li><a href="#">Web Design </a></li>
<li><a href="#">Internet Marketing </a></li>
<li><a href="#">Hosting </a></li>
<li><a href="#">Domain Names </a></li>
<li><a href="#">Broadband </a></li>
</ul>
</li>
<li><a href="#">Contact Us</a>
<ul>
<li><a href="#">United Kingdom</a></li>
<li><a href="#">France</a></li>
<li><a href="#">USA</a></li>
<li><a href="#">Australia</a></li>
</ul>
</li>
</ul>
</td></tr>
</table>

</body>
</html>

dang
08-07-2006, 11:48 AM
I hate to bump up, I really do. But I need to know. :)

Is it at least possible to have two different menu styles on the same page?

If the answer is definately no, that'd fine. At least I can move on and proposed something else for the navigation.

If it's yes, that'd great. Can someone please tell me how it's done or point me in the right direction.

Many thanks.

methanol
08-08-2006, 06:34 AM
You are defining the default ul styles twice, the first time for the top menu, and then *redefining* the default ul styles again with the settings for the bottom menu.

You need to modify the CSS to address the html elements by ID:
for the top menu replace the main ul references with #topnav i.e.:

#topnav {}
#topnav li {}
#topnav li ul {}
#topnav li ul li {}

and address the flyout menu using

#nav {}
#nav li {}
#nav li ul {}
#nav li ul li {}

That way the styles for the two menus shouldn't interfere with each other. try the following, which seems to work in IE6, firefox 1.5 and Opera 9.

/*---TOP EXPANDING MENU--*/
#topnav, #topnav li ul {
margin: 0;
padding: 0;
list-style: none;
width:150px
}

#topnav li, #topnav li ul li {
position: relative;
width:148px;
border: 1px solid #ccc;
}
/* keep folowing styles together..........................*/
#topnav li {float:left;/* hide float from ie5*/}
#topnav li ul {
width:148px;
voice-family: "\"}\"";
voice-family: inherit;
}
#topnav ul {margin-left:0;/* hide margin from ie5*/}

/* keep above styles together .............*/

#topnav li ul {
display:none;
background:#ffffcc
}
#topnav li ul li {border:none;}
/* Styles for Menu Items */
#topnav li a {
display:block;
text-decoration: none;
color: #777;
background: #ffffcc ;
line-height:2em;
height:2em;
padding:0 5px
}
/* this sets all hovered lists to red */
#topnav li:hover a, #topnav li.over a,
#topnav li:hover ul li a:hover, #topnav li.over ul li a:hover {
color: #fff;
background-color: red;
}

/* set dropdown to default */
#topnav li:hover ul li a, #topnav li.over ul li a {
color: #777;
background-color: #fff;
}
#topnav li ul li a { } /* Sub Menu Styles */
#topnav li:hover ul, #topnav li.over ul { display:block } /* The magic */

/*--BOTTOM FLYOUT MENU--*/

#nav, #nav li ul {
margin: 0;
padding: 0;
list-style: none;
width:150px
}

#nav li, #nav li ul li {
position: relative;
width:148px;
border: 1px solid #ccc;
}
/* keep folowing styles together..........................*/
#nav li ul {
margin-left:-16px;/* ie5 fix */
voice-family: "\"}\"";
voice-family: inherit;
}
#nav li {float:left;/* hide float from ie5*/}
#nav li ul {
width:150px;
w\idth:148px;
voice-family: "\"}\"";
voice-family: inherit;
}
#nav li ul {margin-left:0;/* hide margin from ie5*/}

/* keep above styles together .............*/

#nav li ul {
position: absolute;
top: 0;
left:-999em;
}
/* Styles for Menu Items */
#nav li a {
display:block;
text-decoration: none;
color: #777;
background: #99cc66; /* IE6 Bug */
line-height:2em;
height:2em;
padding:0 5px
}

/* this sets all hovered lists to blue */
#nav li:hover a, #nav li.over a,
#nav li:hover ul li a:hover, #nav li.over ul li a:hover {
color: #fff;
background-color: blue;
}

/* set dropdown to default */
#nav li:hover ul li a, #nav li.over ul li a {
color: #777;
background-color: #fff;
}
#nav li ul li a { } /* Sub Menu Styles */
#nav li:hover ul, #nav li.over ul { left:149px; } /* The magic */

dang
08-08-2006, 09:33 AM
Thank you so much!!!

I knew there was probably a simple solution. And I knew the styles were being defined twice in the two menus, I just didn't know how to redefine them.

Thing is, I tried putting the menu name in front of each style like you did (#topnav, #nav) but what I didn't know to do was to do that twice in the first style (#topnav, #topnav li ul, #nav, #nav li ul ).

I kind of feel a little dumb now :D

Thanks again