/    Sign up×
Community /Pin to ProfileBookmark

Sub Menu Help

On my forum webpage I am making a sub menu. The code is:

[code=php]<style type=”text/css”>

.suckerdiv ul{
margin: 0;
padding: 0;
list-style-type: none;
width: 140px; /* Width of Menu Items */
border-bottom: 1px solid #ccc;
}

.suckerdiv ul li{
position: relative;
}

/*Sub level menu items */
.suckerdiv ul li ul{
position: absolute;
width: 130px; /*sub menu width*/
top: 10;
visibility: hidden;
}

/* Sub level menu links style */
.suckerdiv ul li a{
display: block;
overflow: auto; /*force hasLayout in IE7 */
background: #fff;
color: #0000CC;
text-decoration: none;

border: 1px solid #ccc;
border-bottom: 0;
}

.suckerdiv ul li a:visited{
color: black;
}

.suckerdiv ul li a:hover{
background-color: yellow;
}

.suckerdiv .subfolderstyle{
background: url(images/arrow-list.gif) no-repeat center right;
}

/* Holly Hack for IE */
* html .suckerdiv ul li { float: left; height: 1%; }
* html .suckerdiv ul li a { height: 1%; }
/* End */

</style>

<script type=”text/javascript”>

//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=[“suckertree1”] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
var ultags=document.getElementById(menuids[i]).getElementsByTagName(“ul”)
for (var t=0; t<ultags.length; t++){
ultags[t].parentNode.getElementsByTagName(“a”)[0].className=”subfolderstyle”
if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
ultags[t].style.left=ultags[t].parentNode.offsetWidth+”px” //dynamically position first level submenus to be width of main menu item
else //else if this is a sub level submenu (ul)
ultags[t].style.left=ultags[t-1].getElementsByTagName(“a”)[0].offsetWidth+”px” //position menu to the right of menu item that activated it
ultags[t].parentNode.onmouseover=function(){
this.getElementsByTagName(“ul”)[0].style.display=”block”
}
ultags[t].parentNode.onmouseout=function(){
this.getElementsByTagName(“ul”)[0].style.display=”none”
}
}
for (var t=ultags.length-1; t>-1; t–){ //loop through all sub menus again, and use “display:none” to hide menus (to prevent possible page scrollbars
ultags[t].style.visibility=”visible”
ultags[t].style.display=”none”
}
}
}

if (window.addEventListener)
window.addEventListener(“load”, buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent(“onload”, buildsubmenus)

</script>
<div class=”suckerdiv”>
<ul id=”suckertree1″>
<li><a href=”http://cooklikeapro.myfreeforum.org/home.html”>Homepage</a></li>
<li><a href=”http://cooklikeapro.myfreeforum.org”>Forum</a></li>
<li><a href=”http://cooklikeapro.myfreeforum.org/recipes.html”>Recipes</a>
<ul><li><a href=”http://cooklikeapro.myfreeforum.org/starters.html”>Starters</a></li>
<li><a href=”http://cooklikeapro.myfreeforum.org/mains.html”>Mains</a></li>
<li><a href=”http://cooklikeapro.myfreeforum.org/desserts.html”>Desserts</a></li>
<li><a href=”http://cooklikeapro.myfreeforum.org/other.html”>Other</a></li>
</ul>
</li>
<li><a href=”http://cooklikeapro.myfreeforum.org/contactus.html”>Contact Us!!</a></li>
</ul>
</div>
[/code]

It is works but there is a gap between the menu and sub menu. [URL]http://cooklikeapro.myfreeforum.org/mains.html[/URL] is where you can see the menu. Go to recipes and try to select a sub menu. See the sub menu selections are separated from the menu list.

How do I fix this??

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangJun 28.2008 — .suckerdiv ul li ul{
position: absolute;
width: 130px; /*sub menu width*/
[COLOR="Blue"][B]top: -8px;
z-index:1000;[/B][/COLOR]
visibility: hidden;
}

if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
ultags[t].style.left=ultags[t].parentNode.offsetWidth[COLOR="Blue"][B]-7[/B][/COLOR]+"px" //dynamically position first level submenus to be width of main menu item
Copy linkTweet thisAlerts:
@wee2johnauthorJun 28.2008 — great it works. How did you know to put those numbers in. Are they the same numbers no matter what or does it depend on something. Just fro future reference.
Copy linkTweet thisAlerts:
@FangJun 28.2008 — They are related to the font-size. You may want to play with the font-size set for the body and menu.
×

Success!

Help @wee2john spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...