Click to See Complete Forum and Search --> : How to center cascade menu and create link from toplevel bar?


lgodiva
12-16-2005, 08:34 AM
Hi - I'm new to this forum and also to javascript. I'm implementing this cascade menu:
http://javascript.internet.com/navigation/cascade-menu.html
and it's fine except for two things that I can't figure out:
1- how to center the menu on the page
2- how to make one of the toplevel menu items (i.e., one of the menuBar objects) a link rather than having it generate a cascading menu. Other menu examples can do this, but I like the look of this example and want to stick with it. I've tried adding the 'cmd' attribute to the 'Bar' item but really don't know enough about what I'm doing yet to muck around with the .js code.

I would greatly appreciate specific instructions on how to make these two things happen...I will learn js on my own time, just want to get this working for now. Thanks for your help!! :)

Fang
12-16-2005, 08:53 AM
That menu only works in IE. A better menu is Son of Suckerfish (http://www.htmldog.com/articles/suckerfish/dropdowns/)

lgodiva
12-16-2005, 09:30 AM
Thanks, I definitely want to use something that works across all browsers. I figured out how to center the menu (just added 'align="center"' to the <td> that includes the <div>). Now my concern is with all of the odd and specific unit measurements specified in the style code (e.g., "text-indent: -999em"? "w\idth: 13.9em;"?). I'm trying to modify everything to get the menu looking a certain way, but when I change certain things, the menu doesn't look right and I don't know what change caused the problem. For example, suddenly multi-word menu items are displayed as multi-line (1 word/line) unless I add '&nbsp;' between the words. And after I modified the menu items, the hover color didn't extend to the right side of the menu, stopped short after the menu item text. Seems like this example is not so simple to use?? If you could provide some explanation I'd greatly appreciate it!

Fang
12-16-2005, 10:26 AM
Son of Suckerfish
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
"w\idth: 13.9em;" is just another hack (http://centricle.com/ref/css/filters/) that is better not used.

Fang
12-16-2005, 11:03 AM
Put the background color in the anchor and use the nowrap value instead of &nbsp;#nav a {
display: block;
width: 10em;
background:#9cf;
white-space:nowrap;
}The width, also set for other elements, must be large enough to accommodates the menu text.

lgodiva
12-16-2005, 01:39 PM
Ok, getting closer, but the hover color still doesn't fill the entire cascaded menu width...it DOES for the largest item in the list, or when all items are of equal width, but not for shorter ones. Please see this example online for where I'm at: http://webtest.brynmawr.edu/international/committee.html
and http://webtest.brynmawr.edu/international/Templates/CIS_template.dwt is where everything is defined.

Plus, there's an extra space under the menu of the same background color that I can't get rid of (outlined in dark blue on the medium blue background). Do you know how I can get rid of it? It wasn't in the original example.

I would greatly appreciate it if you could answer both questions at the same time. Thanks again for your help!!

Fang
12-17-2005, 03:44 AM
I've had to change a great deal of the document; although it looked almost correct in IE, in other browsers the document fell apart. It should display as required, but I did have to guess a few values.
Notable changes:
added a DTD (http://www.w3.org/QA/2002/04/valid-dtd-list.html) , standards and quiks mode (http://www.w3.org/International/articles/serving-xhtml/#quirks)
most of the CSS
altered the way the 'bars' are displayed

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en"><!-- InstanceBegin template="/Templates/CIS_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Center for International Studies - Committee Members</title>
<!-- InstanceEndEditable --><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link rel="stylesheet" href="cisweb.css" type="text/css">

<style type="text/css">
p {
background: center;
margin: 1em 2em;
}
#nav {
width: 75em;
overflow:hidden;
text-align: left;
margin: 0 auto;
}

#nav, #nav ul {
list-style: none;
line-height: 1;
background: #9EA7D2;
font-weight: normal;
padding: 0;
margin: 0;
FONT-FAMILY: Verdana;
FONT-SIZE: x-small;
}
#container, #nav ul {
border: solid #012349;
border-width: 1px 0;
}

#nav a {
display: block;
width: 13em;
padding: 0.25em 1em;
color: black;
text-decoration: none;
white-space: nowrap;
FONT-FAMILY: Verdana;
FONT-SIZE: x-small;
}
#nav ul a {
width: 15em;
}

#nav a.daddy {
background: url(rightarrow2.gif) center right no-repeat;
}
#nav a.daddy:hover {
background:#FFCE6C url(rightarrow2.gif) center right no-repeat;
}

#nav li {
float: left;
padding: 0;
width: 15em;
}

#nav li ul {
background: #9EA7D2;
position: absolute;
left: -999em;
width: 17em;
font-weight: normal;
FONT-FAMILY: Verdana;
FONT-SIZE: x-small;
border-width: 1px;
margin: 0;
}

#nav li ul ul { /* third-and-above-level lists */
margin: -1em 0 0 17em;
}

#nav li:hover ul ul, #nav li.sfhover ul ul {
left: -999em;
}

#nav li:hover ul, #nav li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul { /* lists nested under hovered list items */
left: auto;
}

#nav a:hover {
background: #FFCE6C;
}

A:hover {color: #6A7DDA}

.bar {
height:12px;
background:#036 url(bar.jpg) no-repeat;
}
</style>

<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+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
Change: <tr>
<td width="100%" height="12" align="left" valign="top">
<div align="left"><img src="bar.jpg" width="100%" height="12"></div>
</td>
</tr>
To: <tr>
<td class="bar">
</td>
</tr>

btw there is no rndSlideShow(5000,0) function. If it is added to the page, separate it from the next function with a semi-colon not a comma.