The mobile navigation panel fails to open

I have a menu that I would like to toggle hide/show by adjusting its top position.

Before logging in, the menu is structured as follows:

<div class="lc">
    <h1><a href="./"><img src="logo.png" /></a></h1>
    <a href="#" id="menuBtn"></a>
    <nav id="mainNav">
        <ul>
            <li><a href="....php">...</a></li>
            <li class="nav-li-..."><a href="....php">...</a></li>
        </ul>
    </nav>
</div>

After logging in, additional items are added:

<div class="lc">
    <h1><a href="./"><img src="logo.png" /></a></h1>
    <a href="#" id="menuBtn"></a>
    <nav id="mainNav">
        <ul>
            <li><a href="....php">...</a></li>
            <li class="nav-li-..."><a href="....php">...</a></li>
            <li class="nav-li-..."><a href="....php">...</a></li>
            <li class="nav-li-..."><a href="....php">...</a></li>
            <li class="nav-li-..."><a href="....php">...</a></li>
            <li class="nav-li-..."><a href="....php">...</a></li>
        </ul>
        <div class="nav-admin">
            <strong>Administrator links:</strong><br />
            <a href="....php?users">...</a><br />
            <a href="....php?user_logs">...</a><br />
            <a href="....php?dealer_logs">...</a><br />
            <a href="....php?herd_logs">...</a><br />
            <a href="....php?php_logs">...</a>
        </div>
    </nav>
</div>  

This CSS code defines the styling:

.lc, nav, h1 {
    background: #fdf6bf;
    background: #FDD;
}
.lc {
    position: fixed;
    z-index: 200;
    width: 14em;
    height: 100%;
    top: 0;
    left: 0;
    padding-top: .5em;
    overflow: auto;
}
    h1 {
        width: 100%;
        font-size: 1em;
        margin-top: 0;
        margin-bottom: .5em;
    }
        h1 a {
            display: block;
            width: 100%;
            text-align: center;
        }
            h1 a img { max-width: 70%; }

    nav ul { list-style: none; }
    nav ul li { padding: .75em 0 .75em 4.25em; }
    nav ul li.is-active { background: #fdf9dc; }
    nav ul li.is-active a:after {
        content: "\232A";
        position: absolute;
        right: .25em;
        top: -.05em;
        font-size: 3em;
        height: 1em;
        line-height: 1em;
        vertical-align: middle;
        color: #c9c49d;
    }

    nav ul a,
    .btn-add {
        display: block;
        position: relative;
        height: 3em;
        padding-left: 1em;
        line-height: 3em;
        vertical-align: middle;
        font-family: 'Exo', sans-serif;
        text-decoration: none;
        color: #4f4e4c;
        font-size: 1em;
        font-weight: 600;
    }
        nav ul a:before,
        .btn-add:before {
            content: '';
            position: absolute;
            right: 100%;
            top: 50%;
            margin-top: -1.75em;
            width: 3.5em;
            height: 3.5em;
            background: url(images/menu_home.png) center center no-repeat;
            background-size: cover;
        }

.nav-show { top: 0; }
.no-scroll { overflow: hidden; }

@media screen and (max-width: 550px) { 
    * { font-size: 1em; }
    nav {
        position: fixed;
        z-index: 180;
        top: -100%;
        left: 0;
        padding-top: 4.5em;
        width: 100%;
        height: 100%;
        overflow: auto;
        -webkit-transition: all 1s ease-in-out;
        -moz-transition: all 1s ease-in-out;
        -o-transition: all 1s ease-in-out;
        transition: all 1s ease-in-out;
        background: #fffad5;
    }
    nav ul li.is-active { background: #fffcea; }

    .lc {
        position: fixed;
        width: 100%;
        height: 3.5em;
        overflow: hidden;
    }

To toggle the menu, I am using the following script:

$(function() {
    $('#menuBtn').on('click', function(e) {
        $('body').toggleClass('no-scroll');
        $('#mainNav').toggleClass('nav-show');
        e.preventDefault();
    });
});

The issue I am facing is with opening the menu after logging in. While it works on desktop PCs, mobile phones (Android) seem to have trouble displaying the menu. I have tested various phones and browsers, but the problem persists consistently on mobile devices.

If anyone has any insights or solutions, please share!

Answer №1

Here's a suggestion for your code: If you want to use position:fixed, you may need to adjust the top attribute by adding some pixels (e.g., around 70px). However, be aware that this adjustment can potentially obscure any additional links you have included in your design.

   @media screen and (max-width: 550px) { 
            * { font-size: 1em; }
            nav {
               position:relative;
                padding-top: 4.5em;
                width: 100%;
                height: 100%;
               -webkit-transition: all 1s ease-in-out;
                -moz-transition: all 1s ease-in-out;
                -o-transition: all 1s ease-in-out;
                transition: all 1s ease-in-out;
                background: #fffad5;
            }
            nav ul li.is-active { background: #fffcea; }

            .lc {
                position: fixed;
                width: 100%;
                height: 100%;

            }
}

Answer №2

Have you attempted adding .nav-show { top: 0; } within the

@media screen and (max-width: 550px) {
as well?

When this .nav-show { top: 0; } is declared before the @media...
The top:-100px value remains.

For further clarification, I discovered this answer.
It provides a thorough explanation.

The issue arises when your element receives top: -100% from nav{ within the @media AND also top:0 from .nav-show. The latter takes precedence.
;)

Answer №3

It appears that the behavior of fixed positioning in the Android browser differs from Firefox and IE.

In particular, when dealing with a fixed div inside another fixed div,
the menu failed to display due to the fact that the .lc element was only 3.5em tall and had an overflow hidden property. I was able to resolve this issue by adding an extra class to .lc to allow it to expand.

.lc-expand { max-height: 100%; }

$('#menuBtn').on('click', function(e) {
    $('body').toggleClass('no-scroll');
    $('.lc').toggleClass('lc-expand');
    $('#mainNav').toggleClass('nav-show');
    e.preventDefault();
});

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

Instant webpage updates upon editing CSS/HTML live

I recently watched a tutorial where a designer was updating CSS with live browser refreshes. What stood out to me was that the browser instantly showed any changes made to the CSS or HTML without needing to manually refresh the page. I am using a Mac with ...

Adjust the size of the font in accordance with the value of the span text

I am looking to adjust the font size based on the value within the span element. The numbers in the class name may vary. Issue: using text() retrieves all values (e.g. 50020) I want to incorporate each() and $this in some way. How can I do this? Thank ...

Unusual actions from the jQuery Steps extension

I am currently utilizing the jQuery Steps plugin (FIND IT HERE). The issue I'm facing lies within an IF statement that is causing the wizard to return to the first step instead of staying on the current indexed step. While all other IF statements are ...

Styling elements conditionally in React JS using inline styles

If the status of this task is 'Completed', I would like to hide the button (similar to adding a display: none property). Code: <Button size="small" style={{display:this.state.task.status == "Completed" ? "none":""}} ...

Engage with Vue.js and traditional JavaScript (plain) in your projects

Exploring the integration of Vue with regular JavaScript has presented a challenge. While some solutions online propose moving all functions to a Vue component, this approach proves impractical for complex or large functions. The task now is finding a way ...

What is the best way to position a div on top of another within a container using Bootstrap?

I have created a div with a date picker inside a form for future fields, but the initial display is next to the table instead of above it. I've searched for solutions similar to my issue, but none seem to work for me. You can view the correct layout ...

Converting HTML to PDF: Transform your web content into

I have a couple of tasks that need to be completed: Firstly, I need to create a functionality where clicking a button will convert an HTML5 page into a .PDF file. Secondly, I am looking to generate another page with a table (Grid) containing data. The gr ...

Receiving a 500 status code upon converting a SqlDataReader into Json format

Getting a status 500 error and not sure where I am going wrong. When I click on the 'Getcustomers' button, the 'GetCustomers' method is called which returns JSON. Script: <script> var MyApp = angular.module("MyApp", []); ...

Accessing the hidden input value of an HTML page in Android with DefaultHttpClient

I previously inquired about a similar issue, but did not provide enough information. So here is the question again, but this time with more detail. On a webpage with html, there exists: <input name="__RequestVerificationToken" type="hidden" value="the_ ...

Using regular expressions to validate input in Javascript

Seeking assistance to validate an input text using the pattern <some_string>:<some_string> in JS/JQuery. For instance: A110:B120 AB12C:B123 I understand this might seem overly simplistic, but any guidance would be greatly appreciated. ...

How to stop PHP code from running before it should in an HTML form script

I recently created a form where the PHP code is located directly underneath the HTML form code within the same file. The issue I am encountering is that when the user fails to fill out all required fields and submits the form, the page immediately displa ...

A div positioned in front of a centrally-located div

Managing a website with numerous headlines can be a challenge. When a user clicks on a headline, a button located 10px to the left of the headline should appear. However, the catch is that the headlines must always remain centered, regardless of whether th ...

Align the checkbox input in the center of a flexbox container

I am in the process of creating a side menu with filters, and I need to design a row that includes an input checkbox along with some accompanying text. However, I am facing an issue where the checkbox does not center properly within the flex container when ...

Identifying the moment a jquery-ui autocomplete appears using Selenium testing

Currently, I am in the process of designing a workflow using selenium and python with a remote webdriver connected to a locally running hub. Within this workflow, one task involves inputting text into a search autocomplete field and then waiting for the r ...

invoking a jQuery function from a form on a prior webpage

I've implemented a search PHP page with a search form that looks like this (Bootstrap classes have been removed): <form id="searchform" name="search" role="form" action="/Search" method="post"> <input type="text" class="form-control" nam ...

Re-enable the jQuery-ui sortable feature after it has been turned off

Here is a snippet of my jQuery code: var status = true; $('#edit').click(function () { if (status) { $('table tbody').sortable({ axis: 'y', update: function (event, ui) { va ...

Creating a JSON file using the attributes and values of HTML tags

I am seeking assistance in generating a JSON file from HTML data using jQuery. The HTML structure consists of multiple departments with similar tags and classes: <div class="department_one"> <h1>Name Of Manufacturer</h1> < ...

What is the best way to transfer form data stored locally to a Django view and then store it in the database?

Is there a way to transfer form data from an offline website to a Django view for database storage? I want to fill out a form, save it in local storage, and then upload the data to the database when I reconnect to the internet. Is there a tutorial or can ...

Issues with jQuery Progress Bar Functionality

As a beginner in jQuery, I am currently working on creating an interactive progress bar using jQuery. My goal is to provide a set of checkboxes on a webpage so that when a visitor checks or unchecks a checkbox, the value displayed on the progress bar will ...

What is the reason behind using '-webkit-backface-visibility: hidden;' to resolve problems with negative margin transitions on iOS/iPad 5.1?

During the process of resolving my issue, I accidentally discovered a solution - but I always prefer to understand the fixes I apply. <ul> <li><img src="something.jpg" /></li> <li><img src="somethingElse.jpg" />< ...