My website features a sidebar menu with nested lists. When hovering over a list item, a sub-list appears. However, I am having an issue where the background color fills the entire sub-list instead of just the first list item. See the images below for clarification.
The first image shows my current attempt, while the second image depicts the desired outcome.
https://i.sstatic.net/qVYsN.png
Below is the code snippet for this functionality:
/* Menu CSS */#cssmenu,
#cssmenu > ul {
background: url(images/highlight-bg.png) repeat;
padding-bottom: 3px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
#cssmenu:before,
#cssmenu:after,
#cssmenu > ul:before,
#cssmenu > ul:after {
content: "";
display: table;
}
#cssmenu:after,
#cssmenu > ul:after {
clear: both;
}
#cssmenu {
width: auto;
zoom: 1;
width: 100%;
}
#cssmenu > ul {
margin: 0;
padding: 0;
position: relative;
background-color: rgba(0, 0, 0, 0.7);
}
#cssmenu > ul li {
margin: 0;
padding: 0;
list-style: none;
}
#cssmenu > ul > li {
float: left;
position: relative;
cursor: pointer;
}
#cssmenu > ul > li > a {
padding-top: 6px;
padding-bottom: 6px;
display: block;
color: white;
font-size: 13px;
text-decoration: none;
text-transform: uppercase;
line-height: 18px;
}
#cssmenu > ul > li:hover > a {
background: #d6d6d6; /* Old browsers */
background: -moz-linear-gradient(top, #d6d6d6 0%, #e56e1d 49%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #d6d6d6 0%,#e56e1d 49%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #d6d6d6 0%,#e56e1d 49%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d6d6d6', endColorstr='#e56e1d',GradientType=0 ); /* IE6-9 */
}
#cssmenu > ul > li > a > span {
line-height: 18px;
font-size: 12px;
border-right: rgb(255, 255, 255, 0.5) solid 1px;
padding-right: 38px;
padding-left: 38px;
}
/*
#cssmenu > ul > li.active > a,
#cssmenu > ul > li > a:active {
background-color: rgba(0, 0, 0, 0.7);
}
*/
/* Childs */
#cssmenu > ul ul {
opacity: 0;
visibility: hidden;
position: absolute;
margin: 0;
padding: 0;
z-index: -1;
}
#cssmenu > ul li:hover ul {
opacity: 1;
visibility: visible;
margin: 0;
color: #000;
z-index: 2;
left: 0;
}
#cssmenu > ul ul:before {
content: "";
position: absolute;
top: -10px;
width: 100%;
height: 20px;
background: transparent;
}
#cssmenu > ul ul li {
list-style: none;
padding: 0;
margin: 0;
width: 100%;
}
#cssmenu > ul ul li a {
padding: 6px 26px;
background-color: #e56e1d;
display: block;
color: white;
font-size: 13px;
text-decoration: none;
width: 194px;
border-left: 4px solid transparent;
}
#cssmenu > ul ul li a:hover {
background-color: #ee974f;
}
<ul id="sidebar">
<li><a href='#'><span>Lorem ipsum dolor sit </span></a></li>
<li><a href='#'><span>Amet, consectetur </span></a></li>
<li><a href='#'><span>Adipisici elit, sed </span></a></li>
<li><a href='#'><span>Eiusmod </span></a>
<li><a href='#'><span>Tempor incidunt </span></a>
<ul>
<li><a href='#'><span>Excepteur</span></a></li>
<li><a href='#'><span>Sint obcaecat</span></a></li>
<ul>
<li><a href='#'><span>Obcaecat</span></a></li>
<li><a href='#'><span>Cupiditat</span></a></li>
</ul>
<li><a href='#'><span>Cupiditat non </span></a></li>
<li><a href='#'><span>Proident.</span></a></li>
</ul>
</li>
<li><a href='#'><span>Ut labore et </span></a>
<li><a href='#'><span>Dolore magna aliqua</span></a>
</ul>