Looking to include a toggle button in the menu for both desktop and mobile versions using Bootstrap

When viewing the website on a mobile device, the menu appears as a toggle button. However, on desktop, the menu is displayed without the toggle. Is there a way to show the menu in a toggle button on the desktop version using Bootstrap?

Answer №1

$('.hamberger').click(function() {
$('.hamberger-navbar').toggleClass('active-left');
});
body {
  margin: 0;
  list-style-type: none;
  }
header,
nav {
  display: block;
}
.container-fluid {
  list-style: none;
  font-weight: bold;
  width: 100%;
  text-align: center;
  background-color: #795548;
  height: 50px;
  float: left;
}
#navbar {
  position: relative;
  float:left;
  height: 50px;
  text-align: center;
}
#navbar ul {
  float: left;
  margin: 0px;
  padding: 0px;
  overflow: visible;
}
#navbar li {
  float: left;
  display: block;
  height: 19.5px;
}
#navbar a {
  float: left;
  text-decoration: none;
  color: #e0dbd1;
  font-family: verdana;
}
#navbar li a {
  float: left;
  display: block;
  padding: 15px;
  background-color: #795548;
  text-align: center;
  font-style: verdana;
}
.hamberger {
  display: none;
}
.hamberger {
  position: absolute;
  top: 30px;
  right: 15px;
  z-index: 999999;
  padding: 10px 35px 16px 0;
  cursor: pointer
}

.hamberger span,
.hamberger span:before,
.hamberger span:after {
  content: "";
  position: absolute;
  display: block;
  width: 35px;
  height: 3px;
  border-radius: 1px;
  border-color:#ffffff;
  background: #ffffff;
  cursor: pointer;
}

.hamberger span:before {
  top: -10px;
}

.hamberger span:after {
  bottom: -10px;
}

.hamberger span,
.hamberger span:before,
.hamberger span:after {
  transition: all 300ms ease-in-out;
}

.hamberger.active span {
  background-color: transparent
}

.hamberger.active span:before,
.hamberger.active span:after {
  top: 0;
}

.hamberger.active span:before {
  transform: rotate(45deg);
}

.hamberger.active span:after {
  top: 10px;
  transform: translatey(-10px)   rotate(-45deg);
}

@media (max-width: 1024px){
    .hamberger-navbar {
    position: fixed;
    left: -300px;
    width: 300px;
    transition: all 0.5s;
  }
  .hamberger-navbar.active-left {
    left: 0;
    position: relative;
  }
  .hamberger-navbar.active-left:after {
    position: fixed;
    content: "";
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: -1;
  }
  #navbar {
    float: none;
    height: auto;
    position: relative;
    z-index: 99;
    margin-top: 50px;
  }
    #navbar ul {
    width: 100%;
    float: none;
  }
  #navbar li {
    float: none;
    height: auto;
    width: 100%;
  }
  #navbar li a {
    float: none;
  }
  .hamberger {
    float: left;
    margin: 17px 0 0 10px;
    position: fixed;
    top: 0;
    left: 20px;
    display: block;
  }
}
 @media (max-width: 991px){
  .hamberger-navbar {
    position: fixed;
    left: -300px;
    width: 300px;
    transition: all 0.5s;
  }
  .hamberger-navbar.active-left {
    left: 0;
    position: relative;
  }
  .hamberger-navbar.active-left:after {
    position: fixed;
    content: "";
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: -1;
  }

  #navbar {
    float: none;
    height: auto;
    position: relative;
    z-index: 99;
    margin-top: 50px;
  }
  #navbar ul {
    width: 100%;
    float: none;
  }
  #navbar li {
    float: none;
    height: auto;
    width: 100%;
  }
  #navbar li a {
    float: none;
  }
  .hamberger {
    float: left;
    margin: 17px 0 0 10px;
    position: fixed;
    top: 0;
    left: 20px;
    display: block;
  }
 }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
    <div class="container-fluid">
      <div class="hamberger">
        <span></span>
      </div>
    <nav id="navbar" class="hamberger-navbar">
        <ul>
            <li><a class="active">Home</a></li>
          <li><a class="navigation">About Us</a></li>
            <li><a class="navigation">Products</a></li>
            <li><a class="navigation">Header Style</a></li>
            <li><a class="navigation">Blogs</a></li>
            <li><a class="navigation">Contact Us</a></li>
        </ul>
    </nav>
    </div>
</header>

Take a look at this useful information.

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

Reload a jquery pop up upon closing a pop up window

I have a modal pop up that appears after clicking an ASP button : <div class="form-group"> <asp:Button ID="btnBrand" runat="server" Text="Add brand" CssClass="btn btn-info" OnClick="btnAdd_Click" /> </div> Code Behind : protected ...

Is it possible to verify the user's authentication by confirming the presence of a JWT in their localStorage?

I am currently working on a project that requires JWT authentication. I have set up a registration form and login page where users receive an authorityToken and it is saved in localStorage. Once the user logs into their account : ` $("#btnLogin").click( ...

Using Angular to retrieve JSON data from a static file

Currently, I am attempting to implement this AngularJS example from a tutorial on Login Tutorial Example. Instead of storing the username and password as simple strings, I am trying to retrieve them from a local file. I understand that this may not be the ...

"After executing a loop in JavaScript using jquery.ajax, the success function does not perform

Having trouble passing values from a PHP file to another function in Javascript. Even after a successful FOR LOOP, nothing seems to work within the SUCCESS block. Any suggestions? url1 = 'http://localhost:81/Dashboard/admin/inc/dashboard.php'; $ ...

Can the sidebar be positioned after the div on an HTML page?

Is it possible for the sidebar to remain static until it is reached by scrolling on the page? I want it to be positioned below the Jumbotron and then stick to the left and top when scrolling down. Currently, it's overlapping everything and adjusting z ...

Learn how to fetch user-selected options in Node.js and display the corresponding file contents in a textarea after submission

Hello, I am new to Node.js so please be patient with me. I am struggling to figure out how to retrieve the selected option from a drop-down list after a user submits it and then perform an action based on that choice. Here is an example of what I have in m ...

Toggle the visibility of text boxes based on the checkbox selection

After doing some research, I decided to revise the question after receiving feedback that it was causing some concern. When a checkbox is clicked, the content of the corresponding div should be visible and vice versa. How can I achieve this? Thank you. JQ ...

Divide a JSON dataset into two distinct JSON files and incorporate them within the code

My JSON file structure is as follows: { "rID": "1", "rFI": "01", "rTN": "0011", "rAN": "11", "sID&quo ...

Issue with Angular failing to identify jQuery after transferring the dependency from package.json to bower.json

Initially, my project included angular, angular-bootstrap, and jquery in the package.json file, with everything being compiled using browserify. // package "dependencies": { "angular": "~1.4.6", "angular-bootstrap": "~0.12.2", "jquery": "~2.1. ...

How can I create a more spacious and stylish JTextField for my address bar?

I am working on developing my Java skills by creating a custom browser. Is there a way to adjust the size and shape of the address bar, which is currently implemented as a JTextField with Swing's default settings? Here is the code snippet I am using: ...

Navigate to the subsequent frame once the HTML5 video finishes playing

I have created a basic HTML webpage with a fullscreen background video (not set to loop) using the Vide plugin. Everything is working well, but I want the video to pause on the last frame to showcase a logo I have included at the end. This functionality w ...

PHP - Easily send emails with attachments

Below are the codes I am using to send an email with an attachment: if (isset($_POST['submit'])) { @$name=stripslashes($_POST['name']); @$last_name=stripslashes($_POST['last_name']); @$phone=stripslashes($_POST['phone&a ...

"Encountered an HTTP 400 error when trying to retrieve content from a Persian URL using file

As a beginner, I am facing an issue with a URL that contains Persian language characters. For instance: http://tabnak.ir/fa/news/577155/ویدیوی-درگیری-نیروهای-سیا-و-پنتاگون-در-سوریه-با-همدیگر-ویدیوهایی ...

Technique in CSS/SASS to repair a div

Seeking a solution for fixing divs with text in CSS. I am aware of the background-attachment: fixed; property which creates a fancy effect. Is there a similar property to "fix" divs with text or how can this be achieved in Typescript? Your insight would be ...

Maintaining an onExit function in the ui-router framework

I am trying to implement an animation on an element within a page when the user is transitioning out of a state. Here is my current code snippet: { ....., views: { ... }, onExit: function(){ someEle.classList.remove("someClass"); // ...

Item on the menu has been pushed lower in the list

There seems to be an issue with the layout of my menu as one item is displaying lower than the others without any clear reason. <html> <head> <title> My Website Homepage </title> </head> <body> ...

Tips for launching a colorbox within a specific div container

I am looking to implement a color box that opens without a popup and only shows/hides inside a specific div. Is it possible to target a div to open the colorbox content? <a href='#myGallery' class='group'>click here</a> &l ...

Are the ajaxSend and ajaxStop events in Jquery not functioning properly?

Having trouble getting the ajaxSend and Stop functions to work properly. I understand that these are global variables, but for some reason I am not able to use them as intended. I never receive an alert when trying to use them in my code. I was hoping to ...

What is the best way to display JSON response as code instead of a string in AngularJS?

When retrieving my article from the database as a JSON object, I encounter an issue with the body content. The HTML codes in the body are displayed as strings within double quotation marks by AngularJS. How can I resolve this? Angular controller snippet: ...

Enabling a checkbox grid for exclusive rectangular selections

Apologies for the confusing title, I struggled to come up with something more fitting. Let's say my client needs a square area on their homepage where they can upload images that will be placed within various boxes in a grid. The available box optio ...