CSS Library: Horizontal CSS Menus: Here
SuckerTree Horizontal Menu
Author: Dynamic Drive
SuckerTree Horizontal Menu is a CSS and DOM hybrid menu that's list based and supports multiple levels of sub menus. The trick to SuckerTree is a small adoptable piece of JavaScript that crawls the inner levels of a list menu and assigns the appropriate show/hide and positioning behavior to them. You can even have multiple SuckerTree menus on the same page.
See also: SuckerTree Vertical Menu.
Demo:
The two bullet images used:
![]()
The CSS:
Got a question or need help customizing this CSS code? Post it in the CSS Forums. If you have a comment or suggestion instead, post it in the comments section below.
Comment Pages 23 of 30 pages « First < 21 22 23 24 25 > Last »
Just give set a background to the link items in the submenu's:
/* Sub level menu links style */
.suckertreemenu ul li ul li a{
background-color: #FFFFFF;
}
/*1st sub level menu*/
.suckertreemenu ul li ul
{
position: absolute;
top: 1em; /* no need to change, as true value set by script */
display: block;
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
width: 145px;
padding: 2em 0 0 0;
margin:0;
white-space:normal;
}
And then in script:
function buildsubmenus_horizontal(){
for (var i=0; i<menuids.length; i++){
var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
for (var t=0; t<ultags.length; t++){
if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
}
else{ //else if this is a sub level menu (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.getElementsByTagName("a")[0].className="subfoldericon"
}
ultags[t].parentNode.onmouseover=function()
{
//this.getElementsByTagName("ul")[0].style.visibility="visible"
this.getElementsByTagName("ul")[0].style.left="0em"
}
ultags[t].parentNode.onmouseout=function()
{
//this.getElementsByTagName("ul")[0].style.visibility="hidden"
this.getElementsByTagName("ul")[0].style.left="-999em"
}
}
}
}
This is my frameset code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Le Diamant</title>
</head>
<frameset rows="276,*" cols="*" framespacing="0" frameborder="NO" border="0">
<frame src="menu.html" name="topFrame" scrolling="NO" noresize >
<frame src="news.html" name="mainFrame">
</frameset>
<noframes><body>
</body></noframes>
</html>
<head>
<style type="text/css">
/*Credits: Dynamic Drive CSS Library */
/*URL: http://www.dynamicdrive.com/style/ */
.suckertreemenu ul{
margin: 0;
padding: 0;
list-style-type: none;
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
font-style: normal;
font-weight: bold;
color: #FFFFFF;
background-color: #006633;
border: 1px solid #000000;
text-align: center;
white-space: normal;
line-height: normal;
font-variant: normal;
text-transform: capitalize;
text-decoration: none;
}
/*Top level list items*/
.suckertreemenu ul li{
position: relative;
display: inline;
float: left;
background-color: #006633;
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
font-style: normal;
font-weight: bold;
font-variant: normal;
text-transform: capitalize;
color: #FFFFFF;
text-decoration: none;
}
/*Top level menu link items style*/
.suckertreemenu ul li a{
display: block;
width: auto;
padding: 1px 4px;
border: 1px solid black;
text-decoration: none;
color: white;
overflow: visible;
}
/*1st sub level menu*/
.suckertreemenu ul li ul{
left: 0;
position: absolute;
width: auto;
top: 1em;
display: block;
visibility: hidden;
border: thin solid #000000;
overflow: visible;
}
/*Sub level menu list items (undo style from Top level List Items)*/
.suckertreemenu ul li ul li{
display: list-item;
float: none;
width: auto; /*Width of sub level menu list items*/
}
/*All subsequent sub menu levels offset after 1st level sub menu */
.suckertreemenu ul li ul li ul{
left: 159px; /* no need to change, as true value set by script */
top: 0;
width: auto; /*Width of subsequent sub menu items*/
}
/* Sub level menu links style */
.suckertreemenu ul li ul li a{
display: block;
width: auto;
color: white;
text-decoration: none;
border: 1px solid #000000;
width: auto;
}
.suckertreemenu ul li a:hover{
background-color:#003300
color: white;
border: 1px solid #000000;
}
/*Background image for top level menu list links */
.suckertreemenu .mainfoldericon{
background-color:#006633;
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
font-style: normal;
font-weight: bold;
font-variant: normal;
text-transform: capitalize;
color: #FFFFFF;
text-decoration: none;
border: 1px solid #000000;
}
/*Background image for subsequent level menu list links */
.suckertreemenu .subfoldericon{
border: 1px solid #000000;
}
* html p#iepara{ /*For a paragraph (if any) that immediately follows suckertree menu, add 1em top spacing between the two in IE*/
padding-top: 1em;
}
/* Holly Hack for IE \*/
* html .suckertreemenu ul li {
float: left;
height: 1%;
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
font-style: normal;
font-weight: bold;
font-variant: normal;
text-transform: capitalize;
color: #FFFFFF;
text-decoration: none;
}
* html .suckertreemenu ul li a {
height: 1%;
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
font-style: normal;
font-weight: bold;
font-variant: normal;
text-transform: capitalize;
color: #FFFFFF;
text-decoration: none;
background-color: #006633;
}
/* End */
background-color:#000000}
.style4 {
font-size: x-small;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFFFFF;
text-decoration: none;
background-color: #006633;
}
</style>
<script type="text/javascript">
//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/
var menuids=["treemenu1"] //Enter id(s) of SuckerTree UL menus, separated by commas
function buildsubmenus_horizontal(){
for (var i=0; i<menuids.length; i++){
var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
for (var t=0; t<ultags.length; t++){
if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
}
else{ //else if this is a sub level menu (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.getElementsByTagName("a")[0].className="subfoldericon"
}
ultags[t].parentNode.onmouseover=function(){
this.getElementsByTagName("ul")[0].style.visibility="visible"
}
ultags[t].parentNode.onmouseout=function(){
this.getElementsByTagName("ul")[0].style.visibility="hidden"
}
}
}
}
if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<div align="center">
<table width="800" border="0" align="center">
<tr>
Comment Pages 23 of 30 pages « First < 21 22 23 24 25 > Last »









Here is the fix I came up with for IE7 submenu disappearence. A little change to the javascript:
Change the .offsetWidth by -20. You may need to play with the offset if necessary, but this will fix all the submenus.
}
else{ //else if this is a sub level menu (ul)
ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth-20+"px" //position menu to the right of menu item that activated it
ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
}
HOPE THIS HELPS!!!