I successfully implemented a side menu that displays the submenu when hovering over menu items. However, I am encountering two issues: 1. When I hover over a menu item and the submenu appears, the hover state of the menu item disappears. I would like the menu item to remain in the hover state. 2. The submenu block appears transparent, allowing the contents behind it to show through. How can I make it completely opaque?
Here is the code I am using...
<!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" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CSS Drop Down Menus</title>
<style type="text/css">
<!-- * {
margin: 0;
padding: 0;
}
body {
font-family: "Trebuchet MS", Helvetica, Sans-Serif;
font-size: 14px;
} -->
a {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
color: black;
}
#menu {
position: relative;
width:20%;
height:400px;
border:1px solid #000;
}
#menu a {
display: block;
width: 140px;
background-image:url(menuitemhover.png);
}
#menu ul {
list-style-type: none;
padding-top: 5px;
}
#menu li {
float: top;
position: relative;
padding: 3px 0;
text-align: center;
}
#menu ul.sub-menu {
display: none;
position: absolute;
top: -10px;
left: 170px;
padding: 10px;
z-index: 90;
}
#menu ul.sub-menu li {
text-align: top;
}
#menu li:hover > ul.sub-menu {
display: block;
border: 1px solid #ececec;
background-image:url(menuitemhover.png);
}
</style>
</head>
<body>
<div id="menu">
<ul>
<li><a href="#">Home</a>
<ul class="sub-menu" style="border:1px solid #d14836"}>
<li><a href="#">Pages</a></li>
<li><a href="#">Archives</a></li>
<li><a href="#">New Posts</a></li>
<li><a href="#">Recent Comments</a></li>
</ul>
</li>
<li><a href="#">About</a>
<ul class="sub-menu" style="border:1px solid #d14836">
<li><a href="#">Get to know us</a></li>
<li><a href="#">Find out what we do</a></li>
</ul>
</li>
<li><a href="#">Contact</a>
<ul class="sub-menu" style="border:1px solid #d14836">
<li><a href="#">E-mail Us</a></li>
<li><a href="#">Use Our Contact Form</a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>