Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 7485

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T04:16:10+00:00 2024-11-28T04:16:10+00:00

Creating a Hamburger Menu

  • 60k

The hamburger icon is simply a symbol that has come to mean “menu”. It's used to toggle a menu or navigation bar between being collapsed behind the button or displayed on the screen.
gif

Here is how to create it-

1. HTML File

We start by creating our HTML file and initializing two classes to target our elements.

<body>   <div class="menu-btn">     <div class="menu-btn__burger"></div>   </div> </body> 
Enter fullscreen mode Exit fullscreen mode

2. CSS File

Here we start creating and designing our hamburger icon. We start with basic properties such as defining the width, height and the transition. This creates the basic outline of the box.

.menu-btn {   position: relative;   display: flex;   justify-content: center;   align-items: center;   width: 80px;   height: 80px;   cursor: pointer;   transition: all .5s ease-in-out;   border: 3px solid #fff;  } 
Enter fullscreen mode Exit fullscreen mode

pic
To get the middle line (out of the three) of our icon we define width, height and border radius as follows-

.menu-btn__burger {   width: 50px;   height: 6px;   background: #fff;   border-radius: 5px;   box-shadow: 0 2px 5px rgba(255,101,47,.2);   transition: all .5s ease-in-out; } 
Enter fullscreen mode Exit fullscreen mode

pic

To get the other two top and bottom lines-

.menu-btn__burger::before, .menu-btn__burger::after {   content: '';   position: absolute;   width: 50px;   height: 6px;   background: #fff;   border-radius: 5px;   box-shadow: 0 2px 5px rgba(255,101,47,.2);   transition: all .5s ease-in-out; } .menu-btn__burger::before {   transform: translateY(-16px); } .menu-btn__burger::after {   transform: translateY(16px); } 
Enter fullscreen mode Exit fullscreen mode

pic

3. JS File

Here we work with the animation of the hamburger icon. We target the “menu-btn” class and initialize a variable “menuopen” to be false. We add an eventListener “click” which either adds or removes the class “open”.

const menuBtn = document.querySelector('.menu-btn'); let menuOpen = false; menuBtn.addEventListener('click', () => {   if(!menuOpen) {     menuBtn.classList.add('open');     menuOpen = true;   } else {     menuBtn.classList.remove('open');     menuOpen = false;   } }); 
Enter fullscreen mode Exit fullscreen mode

4. Final Touch

At last, we need to retouch our CSS for the final animation. Here our middle line moves to the left and other two rotate to 45 deg on click.

.menu-btn.open .menu-btn__burger {   transform: translateX(-50px);   background: transparent;   box-shadow: none; } .menu-btn.open .menu-btn__burger::before {   transform: rotate(45deg) translate(35px, -35px); } .menu-btn.open .menu-btn__burger::after {   transform: rotate(-45deg) translate(35px, 35px); } 
Enter fullscreen mode Exit fullscreen mode

Here is the final preview-

Hope it helps!!!

beginnerscodenewbietutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.