Creating a user-friendly mobile navigation bar

Can someone help me with the code to create a button that displays the navigation bar when needed and hides it when not in use, similar to the one on apple.com? I'm working on this for a mobile device and would appreciate any suggestions or corrections! Here's what I have so far:

.nav {
    background: -webkit-linear-gradient(top left, #3c8dbc 0%, #307196 100%);
    background: linear-gradient(to bottom right, #3c8dbc 0%, #307196 100%);
    width:150%;
    height:14%;
    position:fixed;
    left:0;
    top:0;
    list-style-type:none;
    text-decoration:none;
}

.nav ul li {
    list-style-type:none;
    text-decoration:none;
    color:white;
    padding:2%;
    font-size:80%;
    list-style-position: inside;
    display:inline-block;
    background-color:#63A4C9;
    border:2px solid white;
    width:10%;
    width:60%;
    top:14%;
    left:0;
}

.nav a:link {
    color:white;
    padding:1%;
    padding-left:2%;
    text-decoration:none;
    list-style-position: inside;
    list-style-type:none;
}
.nav a:hover {
    background-color:white;
    color:#3c8dbc;
}
.nav a:active {
    color:white;
    background-color:#3c8dbc;
}
.nav a:visited {
    color:white;
    background-color:#3c8dbc;
}

Your feedback is greatly appreciated :)

Answer №1

If you want to hide a navigation bar and display it when clicking on a button, you can achieve this using JQuery. Take a look at the following example:

.nav{display:none;} /*Add these styles in your CSS */
.stacked{
   position:relative;
   z-index:9999;
   border:1px solid #ccc;
   color:#ccc;
   padding:5px;
   width:36px;
   background:#000
}

Here is a simple JQuery script:

<script>
$(document).ready(function(){
  $(".stacked").click(function(){
    $(".mobile").toggle(100);
  });
});

Now let's add the HTML elements:

<div class="stacked">Menu</div>
<div class="nav mobile">
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>

Don't forget to include JQuery before the closing </body> tag if you haven't already:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

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

After sending the directories, an unusual issue arose that caught me off guard

Here is the code I have written:- const express = require("express"); const app = express(); app.get("/", function (req,res) { res.send("<h1>Hello World</h1>"); res.send(__dirname + '\\index. ...

What is the best way to transmit an array of POST data from a form using ajax?

I am striving to achieve a functionality where the values of checkboxes in a form are automatically sent to a PHP file to filter an SQL database and update a specific part of the HTML page without needing to reload the entire page. Here are the steps that ...

Material-UI Issue: Why is makeStyles not working as expected?

Encountered Error: TypeError: Object(...) is not a function 13 | import { connect } from 'react-redux'; 14 | 15 | > 16 | const useStyles = makeStyles(theme => ({ 17 | ...theme 18 | })); 19 | Code Snippet: const useStyles ...

Optimizing CSS With jQuery During Browser Resize

I am currently facing an issue with recalculating the height of the li element during window resizing or scrolling. Strangely, on page load, the height is no longer being re-calculated and set to the ul's child height. Here is the code I have written ...

Complete the submission of a form containing a dropdown field

I'm looking to accomplish a seemingly simple task, but I'm unsure how to do it: Within my table of records, I want to include a select field that displays different views based on the selection. Here's an example of what my select field loo ...

Pressing enter on the pop-up will activate the submit buttons on the landing page

I am facing an issue with a page that contains two submit buttons and a popup (with the ID: addPopup) that also has a submit button. When the Enter key is pressed on the popup, the first submit button on the main page is triggered instead of the one on the ...

At which location do you configure the applicationIconBadgeNumber?

Can anyone guide me on how to set up the applicationIconBadgeNumber for a React Native / Expo application on both iOS and Android platforms? I am currently using React Native, Visual Studio Code, and Expo. Where should I look to configure this feature? O ...

What is the best way to eliminate the ' from every element in an array in this situation?

My form has hidden fields with values enclosed in single quotes like 'enable'. Using jQuery, I extract these values and push them into an array. This array is then sent to a PHP file using JavaScript through the url attribute of the jQuery AJAX m ...

The condition in a Typescript function that checks for strings will never evaluate to true

I encountered a strange issue with a TypeScript condition in a function. Here is my current code, where the parameters are passed from outside: getLevel(validation: string, status: string): string { let card = ""; if (validation == &qu ...

What is the best way to implement a subquery using EXISTS in Knex?

I'm currently facing challenges while constructing a query using knex, specifically when it comes to incorporating the 'WHERE' clause with the condition EXISTS (SELECT * FROM caregiver_patient WHERE patient_id IN (0,1)). Below is the origin ...

uncertainty about the process of deleting an HTML dropdown item element

I'm in the process of building a dynamic menu that changes based on whether a user is logged in on a webpage. Check out the HTML code I've used (Bootstrap 4): <div class="dropdown" id="account_info"> <butto ...

Minimize the length of the styled-component class name in the upcoming iteration

Dealing with styled-components in Next along with React can pose a challenge when it comes to ensuring proper rendering of the styled components. To tackle this issue, Next offers the compiler.styledComponents flag within the next.config.js file like so: c ...

Jquery Query: Is it possible to incorporate variables into CSS properties?

I manage a website that supports multiple languages, and I want to adjust the position of my container based on the selected language. To achieve this, I attempted the following code: prop = lang == 'ar' ? 'right' : 'left'; $ ...

Generate the MD5 hash of the image that was uploaded

I'm currently working on a method that retrieves posted files. Can anyone suggest the optimal way to calculate the MD5 hash and where it should be implemented? public void ProcessRequest(HttpContext context) { if (context.Request.Fi ...

Tips on avoiding the collapse of the right div when positioned under a left float in a full page layout

Trying out a full page layout for the first time, with a left div serving as a block style nav. #admin_nav { width: 230px; height: 100%; background-color: #f9f9f9; border-right: 1px solid #ddd; float: left; } The content is on the rig ...

Chrome browser is experiencing an issue with the Modal RadWindow not closing properly

In my main "Report" page, there are actions available to the user that open a modal RadWindow. The user can then take actions within the modal window, click Save, and the modal window should close while the main grid refreshes. While this functionality wo ...

Is it possible to seamlessly transition from regular text to italic text?

Wondering if there is a possibility to create a hover effect where regular text, used as an anchor, smoothly transitions into oblique or italicized text with an underline to indicate it is a clickable link. Here's a representation of what I have in m ...

Struggling with JavaScript's while loops and if statements :(

I am working on creating a function that will randomly select global variables based on a number and add them to an array. This process will be repeated 5 times for an online 2D game. The idea is to have cards with information that can later be used to pla ...

Steps for deactivating a textbox upon checkbox activation

When I try to implement the instructions from the textbook, I'm encountering an issue where clicking on the checkbox doesn't disable the textbox on my website. <form action="#"> Billing Address same as Shipping Address: <input ...

Changing Font Awesome Icon with React onClick Event

My dilemma involves a listing of items, each accompanied by a "caret-down" icon. My goal is for clicking on the icon to reveal more information beneath the item, while changing the icon to "caret-up". Subsequently, clicking on the icon again should hide th ...