I am facing an issue with the code snippet below:
.btn-menu:hover .btn-menu__bars::before{
transform: translateY(-0.5875rem);
}
.btn-menu:hover .btn-menu__bars::after{
transform: translateY(0.5875rem);
}
Is there a way to make this hover effect only apply to the hamburger button, and not the close button?
$('.btn-menu').on('click', function() {
$('body').toggleClass('menu-open');
});
.btn-menu {
display: flex;
align-items: center;
justify-content: center;
min-height: 38px;
padding-left: 0;
padding-right: 0;
border: none;
background-color: transparent;
color: inherit;
cursor: pointer;
transition: transform 0.6s cubic-bezier(0.075, 0.82, 0.165, 1);
}
.btn-menu__bars {
position: relative;
width: 40px;
height: 2px;
}
.btn-menu__bars:before, .btn-menu__bars:after {
content: "";
display: block;
position: absolute;
left: 0;
width: 100%;
height: 100%;
background-color: #000;
transition: transform 0.6s cubic-bezier(0.075, 0.82, 0.165, 1);
}
.btn-menu__bars:before {
transform: translate(0, -5px);
}
.btn-menu__bars:after {
transform: translate(0, 5px);
}
.menu-open .btn-menu .btn-menu__bars:before {
transform: rotate(45deg);
}
.menu-open .btn-menu .btn-menu__bars:after {
transform: rotate(-45deg);
}
/* How can I limit this effect to only the burger button? */
.btn-menu:hover .btn-menu__bars::before{
transform: translateY(-0.5875rem);
}
.btn-menu:hover .btn-menu__bars::after{
transform: translateY(0.5875rem);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn-menu" type="button" style="background-color: red;">
<i class="btn-menu__bars" aria-hidden="true"></i>
</button>