Here is the code snippet I am working with:
function myFunction(x) {
x.classList.toggle('change');
}
body,
hmtl {
background- color: black;
}
.text {
color: Black;
}
a {
text-decoration: none;
}
.container {
display: inline-block;
cursor: pointer;
}
.bar1,
.bar2,
.bar3 {
width: 39px;
height: 30px;
border-radius: 90px;
background-color: blue;
margin: 20px 0;
transition: 0.4s;
}
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px);
transform: rotate(-345deg) translate(-9px, 6px);
height: 100px;
position: relative;
top: -100px;
width: 200px;
background- color: blue;
border-radius: 100px;
}
.change .bar2 {
transform: rotate(3000deg);
width: 100px;
height: 200px;
position: relative;
left: 200px;
background-color: blue;
top: -100px;
border- radius: 100px;
}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px);
transform: rotate(45deg) translate(-8px, -8px);
background-color: blue;
width: 200px;
height: 200px;
position: relative;
left: 100px;
bottom: 200px;
opacity: 1! important;
border-radius: 100px;
}
.change .text {
color: black;
font-size: 10px;
position: relative;
top: -200px;
background-color: green;
display: block;
}
<a id="mobile-nav" href="#">
<div class="container" onclick="myFunction(this)">
<div class="bar1">
<p class="details"></p>
</div>
<div class="bar2"></div>
<div class="bar3"></div>
<div class="text">Hello</div>
</div>
</a>
I am trying to achieve a functionality where only the first element .bar1
can be toggled while the other two elements .bar2
and .bar3
react accordingly. However, I am facing issues as currently all three elements toggle at once even though they are part of different containers. How can I establish separate containers for each element and still have them linked so that when one is clicked, the others react in response?