Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
How I can turn my burger menu into a cross?

I would like that when we click on my menu it turns into a cross, I do not understand why it does not work. What would be nice is to be able to launch an animation when another one ends in css

The goal of the animation is that the top and bottom spans disappear and the two small spans in the middle grow and turn 45 degrees.

Thanks for your help, here is my code on codepen below

https://codepen.io/JulienMtau/pen/abOBREK

.icon-menu {
  cursor: pointer;
  width: 30px;
  height: 24px;
  position: relative;

  & > span:first-child {
    transition: width 0.2s;
    position: absolute;
    top: 50%;
    background: black;
    width: 40%;
    height: 1px;
  }

  & > span:last-child {
    transition: width 0.2s, transform 0.2s;
    position: absolute;
    top: 50%;
    transform: translateX(150%);
    background: black;
    width: 40%;
    height: 1px;
  }

  & > span:nth-of-type(2) {
    transition: width 0.2s, margin-left 0.2s;
    position: absolute;
    top: 50%;
    width: 100%;

    &::before,
    &::after {
      content: "";
      position: absolute;
      width: 100%;
      height: 1px;
      background: black;
    }

    &::before {
      transform: translateY(-7px);
    }
    &::after {
      transform: translateY(7px);
    }
  }

  .active:first-of-type {
    animation: burgerToCrossForFirst 1s;
  }

  .active:nth-of-type(2) {
    transition: width 0.2s, margin-left 0.2s;
    width: 0%;
    margin-left: 50%;
  }

  .active:last-of-type {
    animation: burgerToCrossForLast 0.2s;
  }
}

@keyframes burgerToCrossForFirst {
  0% {
    width: 50%;
  }

  50% {
    width: 100%;
  }

  100% {
    transform: rotate(45deg);
  }
}

@keyframes burgerToCrossForLast {
  0% {
    width: 50%;
    transform: translateX(100%);
  }

  50% {
    width: 100%;
    transform: translateX(0%);
  }

  100% {
    transform: translateX(0%) rotate(-45deg);
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

   $('.btn').click(function () {
            $(this).toggleClass("click");
        });
    .btn {
        position: absolute;
        top: 15px;
        left: 45px;
        height: 45px;
        width: 45px;
        text-align: center;
        background: #1b1b1b;
        border-radius: 3px;
        cursor: pointer;

    }

    .btn span {
        color: white;
        font-size: 28px;
        line-height: 45px;
    }

    .btn.click span:before {
        content: '\f00d';
        /* cross icon */
    }
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="style.css">
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>


<body>
    <div class="btn">
        <span class="fas fa-bars"></span>
    </div>


</body>

</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!