I am currently working on a project using only HTML & CSS. I am wanting to make the menu button only display the dropdown items when it is clicked, and have an "x" button that will close them when it is clicked. I am able to make the menu dropdown on hover but am having no luck with it on click without JavaScript.
Does anyone know how I might be able to do this with just HTML & CSS? Here is the HTML & CSS that I have as of right now:
.header-menu {
background-color: #fff;
font-family: "Noto Sans", sans-serif;
font-size: 18px;
}
.header-menu-items {
display: none;
z-index: 1;
max-width: 100%;
overflow-wrap: break-word;
font-weight: 900;
}
.a {
color: #000;
padding: 10px;
text-decoration: none;
}
.search {
display: none;
}
.search-icon {
display: none;
}
.header-menu-items hr {
color: #d0d0d0;
background-color: #d0d0d0;
height: 1px;
border: none;
}
.header-menu-btn {
text-align: left;
background-color: #ff3b3b;
color: #fff;
font-size: 20px;
font-weight: 600;
padding: 10px 0;
border: none;
cursor: pointer;
width: 100%;
margin-bottom: 10px;
padding-left: 10px;
}
.header-menu:hover .header-menu-items {
display: block;
}
<div className="header-menu">
<button className="header-menu-btn">Menu</button>
<div className="header-menu-items">
<div>
<a className="a" href="">
Shirts
</a>
<hr />
<a className="a" href="">
Pants
</a>
<hr />
<a className="a" href="">
Shoes
</a>
<hr />
<a className="a" href="">
T-shirts
</a>
<hr />
<a className="a" href="">
Accessories
</a>
<hr />
</div>
</div>
</div>