I have created a menu dropdown from the code below but when I hover over the dropdown button it works as expected. However, when I then hover over the dropdown itself (not the button) the menu keeps appearing. How can I make it so the menu dropdown would only appear when the button is hovered over?
.dropdown-content {
position: absolute;
z-index: 1;
opacity: 0;
visibility: none;
transition: all .25s ease-in-out;
}
.dropdown:hover .dropdown-content {
opacity: 1;
visibility: visible;
}
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
2
Answers
none
isn’t a valid option for thevisibility
style. (Or at least a non-standard option?) The browser is essentially doing its best to fix the problem, and the result (at least for me) is that the element is there on the page (and thus hoverable) but not shown.Use
visibility: hidden;
instead ofvisibility: none;
simply use
visibility : collapse;
instead ofvisibility : none;
also use this css for visibility: