Your CSS is missing a means to display the ‘open’ state for the dropdown menu.
You can do this by using a :hover selector on the parent li to change its display property.
li:hover ul {
display: block;
}
There are a few other issues with your code that you’ll need to address as well.
Your HTML is invalid, I would suggest passing that through https://validator.w3.org/ to get some clues on where it’s not quite right.
You’re also likely to have problems with this chunk of CSS as well:
ul {
transform: translateY(-110%);
padding: 0;
margin: 0 auto;
float: right;
margin-right:30px;
}
You’re effectively doing a transform: translate
on all ul
elements on the page which means it’s also going to affect the position of your dropdown menu.
I’m trying to get a drop down navigation on the right side of the navi bar, however my dropdown items are not appearing at all and my button gives me a blue line as though its a link, when hovered over.
HTML:
<div>
<div class="dropdown ">
<nav class="navbar navbar-expand-md bg-dark navbar-
dark py-3">
<a id="name" href="index.html">
<img src="images/headericon.png" width="40" height="40" class="d-inline-block align-top" alt="">
</a>
<h5 style="font-size: 22px" class="ml-2 text-info mt-2">webname</h5>
</div>
<ul>
<li><a href="#">User12345</a>
<ul>
<li><a href="#">Profile</a></li>
<li><a href="#">Favourite</a></li>
<li> <a href="#">Sign Out</a></li>
</ul>
</li>
</ul>
</div>
</nav>
CSS:
body {
font-family: arial;
margin: 0;
padding: 0;
}
.dropdown {
margin: 0 auto;
}
ul {
transform: translateY(-110%);
padding: 0;
margin: 0 auto;
float: right;
margin-right:30px;
}
ul li {
position: relative;
list-style: none;
display: inline-block;
box-sizing: border-box;
}
ul li a {
display: block;
padding: 0 15px;
color: #D3D3D3;
text-decoration: none;
line-height: 60px;
font-size: 20px;
}
ul li a:hover {
background: #494c4e;
}
ul ul {
position: absolute;
top: 60px;
display: none;
}