Hey there! I'm working on a page that features a dropdown navbar. My goal is to create a secondary dropdown that appears to the right when hovering over an li element within the initial dropdown. Any tips on how to accomplish this? Thanks in advance!
I copied the code from w3schools for reference.
Here's my current code:
ul {
list-style-type: none;
top: 0;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #2d2d2d;
}
li {
float: left;
}
li a, .curso {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .desplegable:hover .curso {
background-color: #c40105;
}
li.desplegable {
display: inline-block;
}
.grupo-desplegable {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.grupo-desplegable a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.grupo-desplegable a:hover {background-color: #f1f1f1}
.desplegable:hover .grupo-desplegable {
display: block;
}
Below is the HTML structure:
<ul>
<li class="desplegable">
<a href="#" class="curso">1º ESO</a>
<div class="grupo-desplegable">
<a href="#">Grupo A</a>
<a href="#">Grupo B</a>
<a href="#">Grupo C</a>
<a href="#">Grupo D</a>
</div>
</li>
<!-- Other similar list items -->
</ul>
The desired hierarchy is as follows:
- 1º ESO
- Grupo A
- Subitem A
- Subitem A
- Subitem A