Is there a way to convert my desktop menu into a hamburger menu for mobile devices?

I currently have a side menu on my website, but I would like it to change into a hamburger menu when accessed from a mobile device. I am using bootstrap libraries and wondering if they can assist in this transition. Below is an example of the current structure:

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>example</title>
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086a67677c7b7c7a6978483d263a263a">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">

    <style>

        div {
            border: solid black 1px;
            margin: 0 !important;
            padding: 0 !important;
            max-width: none !important;
            width: 100%;
        }

        .menu {
            text-align: center;
        }

        button {
            margin: 20px;
        }
    </style>
</head>


<body>
    <div class="container">
        <div class="row">
            <div class="col-3">
                <div class="menu">
                    <button>Content 1</button><br>
                    <button>Content 2</button><br>
                    <button>Content 3</button><br>
                    <button>Content 4</button><br>
                    <button>Content 5</button><br>
                    <button>Content 6</button><br>
                    <button>Content 7</button><br>
                    <button>Content 8</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="61030e0e15121513001121544f534f53">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
</body>

Answer №1

Utilizing Bootstrap makes creating a navigation bar much simpler. Here is an example of how to implement it:

<nav class="navbar navbar-expand-md navbar-light bg-light">
    <a class="navbar-brand" href="#">
        <img src="yourlogo.com"  class="d-inline-block align-top" width="32" height="32" alt="Your logo" />web.com</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation-bar-content" aria-controls="navigation-bar-content" aria-expanded="false" aria-label="Expand navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navigation-bar-content">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="#">About <span class="sr-only">(current)</span></a>
            <li class="nav-item">
                <a class="nav-link disabled" href="#">Products</a>
            </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="search" placeholder="Search..." aria-label="Search">
            <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Submit</button>
        </form>
    </div>
</nav>

On mobile devices, the menu collapses into a hamburger icon for easier navigation. You can confirm this by using developer tools (CTRL + SHIFT + I in Chrome).

Ensure that you have a functional search feature for the search field to work properly. Additionally, consider adding a dropdown menu, but keep in mind that JavaScript must be included as well.

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

Is there a way to merge two :not() selectors together?

Attempting to achieve the following: :not(h1) > a, :not(figure) > a { background: #859900; } Encountering an issue as figure>a is matching with :not(h1)>a, and h1>a is matching with :not(figure)>a. How can I merge these selectors? ...

Adjust the dimensions of a box by simultaneously altering both its height and width

I am looking to create a responsive box that automatically adjusts its height when the window width is resized. I have tried using Transform:Translate() to move the picture inside, but so far, the height only changes when I manually adjust the height of ...

New to the world of web design and seeking answers as to why my style is not being applied

After diligently following the courses on CodeAcademy (I know, kind of lame but it's a start), I finally feel confident in my ability to write my own HTML and CSS code. However, when I tried to do so using Sublime Text 3 and opened my HTML file, I not ...

Eliminating unnecessary whitespace between the bottom of the document and an element

I have a HTML page that when scrolled should limit scroll to the document height. It must not exceed the bottom of an element. Here is a screenshot for better understanding: https://i.stack.imgur.com/RaVg8.jpg The scrolling should be limited after the En ...

Creating a flexible grid layout with DIVs that share equal width dimensions

Struggling with my HTML and CSS code, I need a way to structure nested DIV blocks into a responsive grid where each block has the same width. Despite my efforts, nothing seems to work as expected. Currently, the nested DIVs are stacked vertically one on to ...

Utilizing NgStyle and Property Binding in Angular to Manipulate Data (or a Different Approach)

Currently, I am diving into Angular programming and encountering an issue with property bindings. Let me share a snippet of my code: // TS FILE data[ {"id": "1", "name": "tester", "rev": "1"}, {"id": "2", "name": "tester", "rev": "1"}, {"id": "3", "name" ...

Detecting if a physical keyboard is connected using CSS media query

Imagine having a website with keyboard shortcuts, where the goal is to visually display these shortcuts as part of the element they correspond to. When it comes to touch interfaces, especially on mobile phones, this may not be necessary because: Most us ...

Editable JSON data within a table using Twitter Bootstrap

How come I am unable to utilize the bootstrap editable table in this manner? <table id="addElements" data-height="299"> <thead> <tr> <th data-field="id" data-align="right">Item ID</th> < ...

What could be causing my HTML button to malfunction, sir?

I'm new to HTML and CSS, and I've created an HTML code for on/off buttons. However, my buttons are not functioning as expected. I've tried troubleshooting but haven't been able to pinpoint the issue. Here is my HTML snippet: .s { p ...

Customizing Nav Bar Color in Bootstrap

Is there a way I can change the font color of the Nav Bar to white? I'm having trouble figuring out which CSS class to use for 'Contact', 'Portfolio', and 'About' as 'Navbar' is already white due to Bootstraps&a ...

How can I ensure the end of the list is clearly visible?

I'm experiencing an issue where the last element in my list is getting cut off. When I check the console logs, I can see that it's rendering properly. If I remove the 'position: fixed' style, I can see the element at the bottom of the l ...

Retrieve CSS height using Jquery, based on the declared value rather than the computed value

In a previous version of jQuery, the default behavior was different. When I use .css("height") and .height(), it gives me the computed height instead of what I actually want. I only need the height value if it is explicitly declared in the CSS for that ele ...

What is the Most Effective Method for Implementing a Unique Font-Family without Sacrificing Loading Speed

I have recently incorporated my own unique font to my website and utilized the code below to specify a custom font-family. Unfortunately, I've encountered an issue where the custom font initially displays as a standard web font while the page is loadi ...

(CSS) Unusual phantom white outline surrounding menu with no visible border

I've just finished creating my first multi-level drop-down menu, but I'm encountering two white border issues. The first white border appears at the bottom of the menu and seems to be related to the padding of the a-elements. The specific area in ...

Utilize Bootstrap 4 to seamlessly integrate a small element between two lengthy items in a row, ensuring a gap

I would like to achieve a similar look to this design. https://i.sstatic.net/p1hq4.png hr { border: none; color: black; background-color: black; height: 5px; margin-top: 10px; } <div class="row code-line"> <div class="col-5 ...

Ways to add more spacing between list items without affecting the position of the bottom div

I'm attempting to achieve a layout similar to an Instagram post, where the list expands but does not push the footer down. In my case, adding margin-bottom to the comment class affects the height of the <div class="post-details-container" ...

How to Implement ASP.NET Authorization While Allowing Access to .css Files?

<authentication mode="Forms"> <forms loginUrl="Login.aspx"/> </authentication> <authorization> <deny users="?"/> </authorization> Currently, I am utilizing forms authentication. However, when I incorporate t ...

Safari browser causing Bootstrap Navbar to overlap due to transforms

I'm facing an issue where a transformed div is overlapping a bootstraped navbar, particularly in Safari as shown below. Can anyone shed some light on why this might be happening? This issue seems to occur only in Safari and not in Firefox or Chrome. ...

Scrolling with JQuery between a webpage's header and footer

I'm having trouble keeping a div at the top of my page, but I want it to stop scrolling before reaching another div. <div class="my-top"><p>This is the top</p></div> <div class="big-one"> <div class="mini1 ...

Creating flexible items with a 1:1 ratio and ensuring that the padding on the left and right of the flex container remains consistent

Whenever I adjust the size of the window, https://i.sstatic.net/Fm3d1.png the flex-container ends up with uneven padding on the left and right, which is less than ideal. So, I am looking for a way to allow the flex-item to resize when the window size c ...