I declared a checkbox
for when I click on the hamburger icon
, the icon animates successfully. But I also want the menu to appear on the screen. I tried setting the opacity: 1
in ilde
state and then the opacaity: 0
in the checked
state but it doesn’t work. HELP
Here is my code
.pop-wrapper {
background-color: black;
position: absolute;
left: 35%;
top: 70px;
text-align: center;
width: 30%;
bottom: 1rem;
opacity: 0;
}
input[type="checkbox"]:checked~.pop-wrapper.m1 {
transform: 0.5s;
opacity: 1;
}
<div className="wrapper">
<div className="hamburger-lines">
<input class="checkbox" type="checkbox" name="" id="" />
<div className="hamburger-l1"></div>
<div className="hamburger-l2"></div>
<div className="hamburger-l3"></div>
</div>
<div className="pop-wrapper">
<div className="popup-m" id="popup-m">
<div className="m1">Home</div>
<div className="m2">Account</div>
<div className="m3">Deposit</div>
</div>
</div>
</div>
I tried setting opacity: 1
in idle and opacity: 0
in checked
state. I am expecting the menu to appear from 0-1 opacity when I click on the hamburger icon but it does nothing.
4
Answers
Instead of .pop-wrapper.m1, you should use .pop-wrapper to target the entire popup wrapper.And you need to use the transition property to animate the change in opacity.:
You should target the .popup-wrapper.
But therefore you need to change the HTML to:
Then change your CSS to:
The
~
selector is the subsequent-sibling combinator, means it will select subsequent sibling only.So, first move the
<input class="checkbox" type="checkbox" name="" id="" />
just before the.pop-wrapper
, also changeinput:checked~.pop-wrapper.m1
toinput:checked~.pop-wrapper
Instead of using opacity to hide and display the div, you can use
display: none; and display: block; properties and by javascript function orgnizing the displaing and hiding the menue you want show so instead of the
you can create
but the place of the button will be out the dive you want to display and this the javascript function to change the css properties
and the final result is