Incorporating a hamburger symbol into an established menu for easy navigation

I have come across a tutorial on creating a navigation menu with a logo positioned to the left. However, I now wish to incorporate a hamburger icon for mobile devices and I am unsure about the process. Despite my efforts to find a suitable tutorial online that caters to my specific requirements, I failed in my attempt. I did try using a tutorial for implementing a hamburger icon but faced challenges and had to start over.

<div class="container">
    <div class="logo">
        <img src="images/logo-large.png" alt="Nathan Ashbury Logo" class="image-1">

    </div>  
<nav>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Coding</a></li>
        <li><a href="#">Photography</a></li>
        <li><a href="#">Contact Us</a></li>
    </ul>
</nav>  
</div>

Answer №1

Creating a Hamburger Menu

<html>
     <head>
    <link rel="stylesheet" type="text/css" href="css/style.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
 </head>

<body>
    <header>
        <h1>Example: Building a hamburger menu</h1>
        <div class="top">
            <a href="#" class="menu_icon"><i class="material-icons">dehaze</i></a>
        </div>
    </header>
    <nav class="menu">
        <a href="#" class="item_menu">home</a>
        <a href="#" class="item_menu">about</a>
        <a href="#" class="item_menu">products</a>
        <a href="#" class="item_menu">services</a>
        <a href="#" class="item_menu">contact</a>
    </nav>
    <main>
        Content of the website.
    </main>

    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
    <script type="text/javascript" src="js/script.js"></script>
</body>

CSS Styles


* { margin: 0 auto; font-family: sans-serif; }

body { margin: 0 auto; }

header {
    height: 70px;
    background-color: #3e739d;
    border-bottom: 1px solid #494949;
    display: flex;
    align-items: center;
    justify-content: center;
}
header > h1 {
    width: calc(100% - 160px);
    text-align: center;
    font-size: 20px;
    color: white;
}
header > .top {
    position: absolute;
    left: 20px;
}
header > .top a.menu_icon i {
    color: #000;
    font-size: 40px;
    padding-top: 5px;
    transition: .2s ease;
}
header > .top a.menu_icon:hover i {
    color: #fff;
}
nav.menu {
    width: 300px;
    min-height: calc(100vh - 121px);
    background-color: #03a9f4;
    position: absolute;
    left: -300px;
    transition: .3s all;
}
nav.menu > a {
    display: block;
    padding: 5px;
    margin: 15px 0 0px 20px;
    color: #494949;
    text-transform: uppercase;
}
main {
    width: 100%;
    padding: 30px;
    box-sizing: border-box;
}
footer {
    height: 50px;
    background-color: #494949;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    bottom: 0;
    position: fixed;
    width: 100%;
}

.menu_show {
    left: 0!important;
}

@media screen and (max-width: 425px) {
    header h1 {
        font-size: 16px;
    }
}
@media screen and (max-width: 360px) {
    nav.menu {
        width: 100%;
        left: -100%; 
    }
}

To enable the menu, showing or hiding the navigation list when the button is clicked, jQuery library is used. Here is the click event of the button with the top class and the toggleClass function of jQuery, adding or removing the menu_show class from the menu to make it visible or invisible.

$(document).ready(function() {
    $("body").on('click', '.top', function() {
        $("nav.menu").toggleClass("menu_show");
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Slider in MaterialUI featuring a vibrant spectrum of colors

Currently, I am delving into MaterialUI and my focus is on creating a range slider. I came across this example that I found useful: https://material-ui.com/components/slider/#range-sliders My goal is to assign different colors to the "high," "medium," and ...

Retrieve the ID from the database and showcase the content on a separate page

My database has a table named "apartments," and I am using the following code to display its contents on a single page: $connect = mysqli_connect("localhost","root","","db_dice"); $query = "SELECT * FROM apartment ORDER BY ID DESC"; $records = mysqli_quer ...

Trouble with displaying HTML content on BrowserField in a BlackBerry device

After successfully solving the issue I posted here, it turns out that the problem was not with parsing, but rather in URL creation. :) Now a new challenge has arisen - the data obtained through parsing contains HTML tags. I attempted to display the HTML c ...

Tips for starting the debugging process with POST and GET requests in Django and the Python Shell

I've encountered an issue with my code where the database is not updating and a new record is not being created. I suspect that there may be a problem with how I am handling the POST data retrieval in my script. Can anyone provide guidance on where to ...

Using the power of HTML5, store data locally on

I am curious about the possibility of using local storage on a different page. I want to track clicks made on one page and display it on another, but I'm not sure how to go about it or if it's even feasible. Any help you can provide would be grea ...

The final element that fractures all its sibling elements positioned absolutely

I am experiencing an issue with a container div that contains 5 absolutely positioned images. When I specify the last image as absolutely positioned, all other images lose their positioning and stack at the top. The container itself is relatively position ...

Utilize the JMX HTML adapter in conjunction with Apache Camel's JMX capabilities

I'm currently utilizing the Sun HTML JMX Adapter to display Camel's exposed JMX beans in an HTML format. I've been working with Spring XML to achieve this, but I'm struggling to establish a connection between the adapter and the JMX age ...

Maintaining the style of `li` elements within a `ul` list while ensuring they all

Struggling to create a menu list item with 4 items that won't fit on one line? Nested divs didn't work when adding padding. Here is my latest HTML and CSS: HTML: <div id="header"> <ul id="menu"> <li><a href="#"& ...

li tag style

I need to insert a check mark inside the <li> tag on the right side. How can I do this? The check mark looks like this: For example: http://jsfiddle.net/HpVcy/ ul li{ padding: 3px 10px 3px 10px; background:url(http://img4up.com/up2/730897458613759 ...

Modify request parameters in real-time using JavaScript

i am seeking assistance with a link request: <a href=index.jsp></> also, i have various divs located elsewhere on the page that contain changing values based on user input or specific conditions: <input id="var1" /> <input id="var2" ...

Choosing the right jQuery selector to target a section that contains div elements

Whenever the h2 element within a section is clicked, I want all the fields in that section to be displayed. For example, if the user clicks on 'Contact Information', the three form inputs (fields) below the Contact Information heading should appe ...

Tips for postponing an action until the webpage is fully loaded

Currently, I am using Selenium in R to perform a specific task. The script I have written enables the program to search for pizza restaurants near a designated geographical coordinate on Google Maps. The script continues to scroll until all restaurant inf ...

Having issues with the Bootstrap tabs code provided in the documentation not functioning correctly

Exploring the world of Bootstrap 5 tabs led me to copy and paste code from the official documentation (https://getbootstrap.com/docs/4.1/components/navs/#javascript-behavior), but unfortunately, it's not functioning as expected: clicking on a tab does ...

Align the present domain using XPath

Is there a way, possibly with a newer version of XPath, to make the following code work: //a/@href[not contains("DOMAIN OF THE CURRENT PAGE")] The DOMAIN OF THE CURRENT PAGE should function as a variable that retrieves the domain - similar to something l ...

The Bootstrap row snag causing text display issues

There seems to be a glitch when the first column has more text than the one next to it. Check out the screenshot provided for reference. Any suggestions on how to fix this issue in Bootstrap? Live Demo: https://jsfiddle.net/oLderkuo/ /* Latest compil ...

Initiate keyframe animation after completion of the transition (CSS)

Can someone assist me with implementing my idea? I want the "anim" animation to start as soon as image1 finishes its transition. My attempted solution: I tried using "animation-delay," but that didn't work for me. The issue is that "animation-delay" ...

The sliding content in the div below the one above it

Currently working on creating my portfolio website, and I have implemented a very dynamic parallax homepage with multiple layers. My goal is to enable one-page scrolling by using vh units. However, I encountered an issue where the div containing the abou ...

Is it possible to dynamically group by one column in a dataset without requiring a trigger function?

I've been working on a script that retrieves values from another page and organizes them into a table alphabetically by Name, City, and District. The current script is functioning well, but I now want to enhance it by grouping the values by city as we ...

What is the best way to style a select element to achieve this appearance?

Currently working on converting a .psd file to html/css and encountering difficulty with a unique looking select element. Struggling to find a suitable example online for reference. Wondering if this design element is indeed a select element. ...

Exploring HTML Data with Python String Manipulation

My goal is to use Python to dynamically extract data from an HTML page that is constantly changing. I have identified that the specific data I am interested in is located between a tag that resembles 'abcd>' and another tag. For example: abcd& ...