I am struggling to create a dropdown menu as shown in this image: Solution for CSS dropdown menu.
Unfortunately, my current code is not producing the desired result: Here is my incorrect solution
This is the code I am using:
.parent-menu li {
display: block;
text-transform: uppercase;
border-bottom:none;
border-top:none;
padding:10px;
border-right:none;
}
.sub-menu-caption, .upper-menu{
border:1px solid red;
}
.parent-menu{
width:100%;
}
.sub-menu {
font-style: italic;
display: none;
width:170px;
height:90px;
position:absolute;
background:black;
margin:10px 0 0 -11px;
font-size:1em;
}
.sub-menu li{
border-bottom:1px solid red;
z-index: 1;
}
.sub-menu li:last-child {
border-bottom: none;
}
.sub-menu-caption{
left:auto;
right:auto;
text-align:center;
}
.sub-menu-caption:hover .sub-menu {
display: block;
border:solid red 1px;
border-top:none;
padding-bottom:5%;
}
<nav id="main-menu" class="section">
<ul class="parent-menu">
<li class="sub-menu-caption">Automobiles
<ul class="sub-menu">
<li><a href="https://auto.ferrari.com/en_US/sports-cars-models/car-range/812-superfast">812 Superfast</a></li>
<li><a href="https://auto.ferrari.com/en_US/sports-cars-models/car-range/gtc4lusso">GTC4Lusso</a></li>
<li><a href="https://auto.ferrari.com/en_US/sports-cars-models/car-range/ferrari-488-gtb">488 GTB</a></li>
<li><a href="https://auto.ferrari.com/en_US/sports-cars-models/car-range/488-spider">488 Spider</a></li>
</ul>
</li>
<li class="upper-menu"><a href="https://auto.ferrari.com/en_US/owners/">services</a></li>
<li class="upper-menu"><a href="https://preowned.ferrari.com/us">pre-owned</a></li>
<li class="upper-menu"><a href="https://auto.ferrari.com/en_US/car-dealers/">Find a dealer</a></li>
<li class="upper-menu"><a href="https://auto.ferrari.com/en_US/register/">my ferrari</a></li>
</ul>
</nav>
There is a slight alignment issue with the dropdown menu and the borders are not extending as expected. What could be causing this problem? And how can I resolve it? And just to clarify, no, I do not work for Ferrari :D Thank you!