In my current setup, I have a nested list within a larger container box. Each ul element has a border-top style applied, while each li element has a border-bottom and padding. The HTML code looks like this:
<div class="menu">
<ul>
<li class="collapsible active">
<i class="fas"></i><a href="#"> Item 1 </a>
<ul class="collapsible__content">
<li>
<a href="#"> Item 2 </a>
</li>
<li><a href="#"> Item 3 </a></li>
</ul>
</li>
</ul>
</div>
The corresponding CSS styles are defined as follows:
.menu {
background: var(--color-primary);
color: #cfc6dc;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.menu a {
color: inherit;
text-decoration: none;
}
.menu ul {
border-top: 1px solid #61676b;
list-style: none;
padding-left: 0;
}
.menu li {
border-bottom: 1px solid #61676b;
padding: 1.5rem;
}
.menu .collapsible__content {
font-size: 1.4rem;
position: relative;
top: 1rem;
padding-left: 2rem;
}
...
The challenge I'm facing is to have a different background color for the active container li element (Item 1) and its block, without affecting the nested li elements when expanded. Additionally, I want the other elements to have a different background color when hovered over. I've attempted to adjust the background color of the "collapsible__content" class and modify it on hover, but the outer margin persists. Can this be achieved with CSS, or should I consider using JavaScript?