Forum Moderators: not2easy
I have gone through several tutorials on how to create a css drop down menu system.
I managed to get one of them to work. However, the child elements are not appearing where i would like them to - ie. just to the right of the parent element.
Any ideas on how to fix this would be appreciated.
Here is the code:
The following is in the head tag:
<script type="text/javascript"><!--//--><![CDATA[//><!--
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>
The following is the html:
<div id="menu">
<ul id="nav">
<li><a href="#"><img src="images/menu/home.gif" class="noborder"></a></li>
<li><a href="#"><img src="images/menu/animage.gif" class="noborder"></a></li>
<li><a href="#"><img src="images/menu/animage2.gif" class="noborder"></a></li>
<li><a href="#"><img src="images/menu/animage3.gif" class="noborder"></a>
<ul>
<li><a href="#">child1</a></li>
<li><a href="#">child2</a></li>
</ul>
</li>
<li><a href="#"><img src="images/menu/animage4.gif" class="noborder"></a></li>
<li><a href="#"><img src="images/menu/contact.gif" class="noborder"></a></li>
</ul>
</div>
The following is the css:
#menu{
position:absolute;
left:50%;
width:200px;
margin-left:-400px;
top:200px;
}
#nav, #nav ul { /* all lists */
padding: 0;
margin: 0;
list-style: none;
line-height: 1;
background-color:none;
}
#nav a {
display: block;
width: 10em;
}
#nav li { /* all list items */
float: left;
width: 10em; /* width needed or else Opera goes nuts */
}
#nav li ul { /* second-level lists */
position: absolute;
background: orange;
width: 10em;
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
}
#nav li:hover ul, #nav li.sfhover ul { /* lists nested under hovered list items */
left: auto;
}
#content {
clear: left;
color: #ccc;
}
.noborder{
border:none;
}
[htmldog.com...]
where they explain that a margin needs to be set for the drop down.