Developing a responsive navigation bar for mobile devices

Can anyone help me with creating a mobile navbar that shows the hamburger icon on smaller screens? I would like the links to appear in blocks when the icon is clicked.

I attempted to make it using an SVG icon for the hamburger and setting the display to none, but I'm struggling to find the right JavaScript code to toggle the links. Any suggestions?

Answer №1

Don't forget to provide the code you've already tried in your next query. It seems like you're delving into CSS/HTML and JS. To kick things off, give this code a shot and refer to the helpful tutorial from w3school: https://www.w3schools.com/howto/howto_js_mobile_navbar.asp

For the hamburger design you mentioned, here's the CSS section:

/* Styling for the navigation menu */
.topnav {
  overflow: hidden;
  background-color: #333;
  position: relative;
}

/* Hide links inside the navigation menu (except for logo/home) */
.topnav #myLinks {
 display: none;
}

/* Styling for navigation menu links */
.topnav a {
 color: white;
 padding: 14px 16px;
 text-decoration: none;
 font-size: 17px;
 display: block;
}

/* Styling for the hamburger menu */
.topnav a.icon {
 background: black;
 display: block;
 position: absolute;
 right: 0;
 top: 0;
}

/* Applying grey background on mouse-over */
.topnav a:hover {
 background-color: #ddd;
 color: black;
}

/* Styling for active link (home/logo) */
.active {
 background-color: #04AA6D;
 color: white;
}

You can find the complete tutorial at the provided link.

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

Elevate state in React to modify classNames of child elements

I have a structured set of data divided into 6 columns representing each level of the hierarchy. When a user makes selections, their chosen location is highlighted with a dynamic CSS class name and displays the relevant data list. I've managed to impl ...

Issues with the animation of the navbar menu button are preventing it from functioning

I have been attempting to incorporate animation when the navbar-button is toggled on smaller screen sizes. Inspired by the design of .navbar-toggle.larr in this particular template, I tried to implement a similar effect. /* ANIMATED LEFT ARROW */ .navbar- ...

Why isn't the button border displaying the color I assigned to it?

After setting a border color to my button, it's not displaying the color when I click on it. Instead, it's showing a different color. How can I resolve this issue? I need some assistance with setting the background of my button to match the imag ...

Creating static pages using React

I am aiming to have my React application operating on the client-side through Amazon S3 (CDN), with news files being created in order to incorporate meta tags for social media sharing, particularly with Facebook. For instance, when a user shares , I envis ...

Positioning elements next to each other in jQuery on mouse over - while also addressing scrolling issues in a div

After tinkering with this interesting concept of mouseover combined with absolute positioning divs on a jsFiddle, I encountered some unexpected results. The code was inspired by a stackoverflow thread on positioning one element relative to another using j ...

using jQuery to show a block element

I'm attempting to determine whether a div with the style display as block then perform an action. Here is an example: This is just an idea I'm trying to implement using jQuery. if ($("#toshow").css("display") == "block"){ }else{ } ...

Tips for populating class attributes from an Angular model

Suppose there is a Class Vehicle with the following properties: public id: number; public modelId: number; public modelName: string; Now consider we have an object that looks like this {id: 1, modelId: 1, modelName: "4"} What is the best way to assign e ...

The function loops through an array of objects and combines specific properties from the objects into a single string

I am currently working on creating a unique custom function that will loop through an array of objects and combine selected object property keys into a single string separated by commas. Let me explain using some code: var products = [ { "id": 1, ...

Having trouble incorporating a Next.js link into the MUI AppBar on my project

As a beginner in learning next js, I've encountered an issue with adding links from next/link to the mui appbar. I was successful using react-router, but now I want to try it with next.js. How can I address this challenge? Should I manually add menu i ...

Tips for sending data to CSS in Angular

I have an Angular application where I need to calculate the width of an element and store it in a variable called finalposition. Then, I want to move this element to the left by (finalposition)px when hovering over it. How can I achieve this styling effect ...

Calculating the height of the browser menubar, toolbar, navigation bar, and bookmarks can be easily achieved using jQuery or JavaScript

How can I use jQuery to calculate the height of the browser and adjust the position of another div element accordingly? What steps do I need to take to achieve this functionality? ...

What Could Be Causing the Issue with My Submit Button's addEventListener Function?

At the initial stages of my project, I am encountering a puzzling issue with my addEventListener. Surprisingly, using onClick with the submit button yields the desired results and displays output in the console. However, attempts to implement addEventListe ...

What is the best way to implement rounded borders using CSS?

Can we use the latest CSS standards to create rounded borders? Unfortunately, this feature is only available in CSS level 3 and above. ...

Invoke the function when you finish typing in React.js

After I finish typing, I want to execute some code. I attempted to use the following script but it didn't work as expected const stopTypingHandler=(e)=>{ let time; clearTimeout(time); time = setTimeout(() => { console.log("click& ...

Adjusting mesh rotation on elliptical curve using mousewheel scrolling

I have arranged several plane meshes in a uniform manner along an elliptical curve. During the animation loop, I am moving them along the ellipse curve using curve.getPointAt with time delta and applying the matrix. Additionally, I am attempting to incor ...

Create a JavaScript onclick popup that hides the destination URL without displaying it

After searching through numerous forums without finding a satisfactory answer, I decided to turn to Stackoverflow for help. Unsure if this is the right category for my question. I'm looking to hide an href link that opens as a popup. It's diffic ...

Adjust the height of the Iframe to match the content within it

After conducting my research, I have not been able to find a solution. Although I am not an expert in jQuery, it seems that the code is not functioning properly. Within the iframe are links that expand when clicked to display content. However, the height o ...

Tips for anchoring a row to the bottom of a Bootstrap webpage

After working with bootstrap, I am looking to position the last row of the page at the bottom in a fixed and responsive size manner. ...

Is there a way to optimize value caching using a customized version of useMemo that remains constant?

I have a complex computation function that could benefit from the useMemo hook. The issue is, I am certain that the arguments for this function will always remain constant. As far as I know, useMemo requires you to list all arguments in an array within its ...

Encountering an issue while attempting to make changes and test a copied GitHub library - npm ERROR! version cannot be located

I'm new to the world of Github forking and pull requests. My goal is to fork a repository, make some changes, and test them out on a project before submitting a pull request. I've already forked the repository and made modifications, but I' ...