I have created my dropdown menu to open on hover of the icon, but I want it to actually open on click instead of hover and close when clicked outside the menu. The icon is a simple burger menu icon on the left hand side of the navbar which opens a dropbar that is attached to the left hand side of the page. How would I achieve what I want to with minimal change to my code?
.search {
display: block;
margin-left: 1300px;
margin-right: auto;
margin-bottom: auto;
margin-top: -30px;
cursor: pointer;
}
.burger-menu {
display: block;
margin-left: 100px;
margin-right: auto;
margin-bottom: auto;
margin-top: 1px;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #000000;
min-width: 250px;
z-index: 1;
}
.dropdown-content a {
color: white;
padding: 30px 16px;
text-align: center;
text-decoration: none;
display: block;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
font-size: 24px;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, "sans-serif";
}
.dropdown-content a:hover {
background-color: #ffffff;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #ffffff;
}
<nav>
<div class="dropdown">
<input type="image" width="30" height="30" src="images/burger-menu.png" class="burger-menu" />
<div class="dropdown-content">
<a href="#">HEADWEAR</a>
<a href="#">HOODIES/JACKETS/LONG SLEEVES</a>
<a href="#">SHIRTS</a>
<a href="#">BOTTOMS</a>
<a href="#">TOTE BAGS</a>
</div>
</div>
<img class="search" src="images/search-icon.png" width="30" height="30">
</nav>
The only way I know of to do this with just CSS is using a checkbox to transition up/down the menu. I see you're using an input tag, so maybe there's another pure CSS way to do this.
Using jQuery, you can get the desired effect using slideToggle()
you need to use