The navigation bar vanishes from sight while scrolling underneath other sections

UPDATE: Problem solved! I discovered that the 'overflow:hidden' inside the #main for the media query was causing the navigation to disappear.

I have a scroll navigation positioned at the top of my webpage. However, as I scroll down, the navigation bar goes underneath the next section and disappears. This issue only started when I added mobile and tablet media queries. Removing the media query stylesheet resolves the problem with the navigation bar display.

HTML Code:

<section id="main">
<nav>   
    <a href="#about">About</a> 
    <a href="#motorcycles">Motorcycles</a> 
    <a href="#coffee">Coffee</a> 
    <a href="#contact">Contact</a> 
</nav>
<h1>Kickstart Cafe</h1> <h2>Coffee shop for the motorcycle enthusiast</h2>

CSS from the media queries:

small phone screen
nav {
    display:none;
}
#main {
    /*background-image: url('../img/beans.jpg');    */
    background-repeat:repeat;
    height:400px;
    overflow:hidden;
    h1 {
        font-size:3.25em;
        position:relative;
        padding-top:35%;
    }
    h2 {
        font-size:1.17em;
    }

}

desktop
@import 'styles';
#main {
    h2 {
        font-size:2.75em;
    }
}
nav {
    z-index:9999 !important;
}

CSS from the main stylesheet:

#main {
margin:0;
padding:0 0 15% 0;
width:100%;
height:auto;
-moz-box-shadow: inset  0 -20px 10px -15px #000;
-webkit-box-shadow: inset  0 -20px 10px -15px #000;
box-shadow:   inset  0 -20px 10px -15px #000;
nav {
    text-align:right;
    width:100%;
    height:50px;
    z-index:9999;
    position:relative;
    top:20px;
    a {
        color:#fff;
        font-size:2em;
        text-decoration:none;
        margin: 0 15px;
    }
}
}
.fixed {
    position:fixed;
    background:rgba(0,0,0,.6);
    top:0;
    a {
        color:#fff !important;

    }
}

jQuery Code:

$(window).scroll(function () {
if ($(window).scrollTop() > 100) {
    $('nav').css('top', $(window).scrollTop());
    $('nav').addClass('fixed');
     } else {
        $('nav').css("top", "20px");
        $('nav').removeClass('fixed');
     }
});

Answer №1

Solving this issue is quite straightforward. You just need to incorporate the z-index CSS property into your code.

z-index: 100

Simply include it within your designated .fixed selector.

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

Issues with the alignment of ion-grid in Ionic/Angular application

I am facing an issue in my ionic/angular project where I am attempting to create two columns within a row using ion-grid, ion-row, and ion-col. However, the content of the second column is unexpectedly appearing below the first column instead of beside it. ...

Gathering information from a website by using BeautifulSoup in Python

When attempting to scrape data from a table using BeautifulSoup, the issue I'm running into is that the scraped data appears as one long string without any spaces or line breaks. How can this be resolved? The code I am currently using to extract text ...

jQuery automatic slider for seamless transitions

I am in need of assistance with the coding for a website I'm currently constructing at www.diveintodesign.co.uk/ChrisMcCrone/index.html The coding being used is sourced from http://jquery.malsup.com/cycle/ The central large image functions as a slid ...

What are some tips for keeping design proportions consistent on mobile apps?

Hey there, I have a question that may seem basic to some, but as a newbie in coding, I appreciate your patience. I've been working on an Ionic app and I'm struggling with maintaining CSS proportions of HTML elements. For instance, here's th ...

"Utilizing multiple class names in Next.js to enhance website styling

Looking for a way to apply multiple classNames in Next.js, especially when dealing with variable classnames? I'm following the component level CSS approach. Take a look at my code and what I aim to achieve: import styles from "./ColorGroup.mod ...

Updates made to CSS are not reflecting on the error 404 page

Unable to Apply CSS Changes to 404 Error Page EDIT: page in question: Right from the start: I have ruled out any relative path issues. I have specified a base href in my header like this: <base href="https://hinnahackers.no/"> I am aware that thi ...

Aligning images and input fields vertically with relative measurements

I'm looking for a way to vertically position two images, one on the left and one on the right, so that they are centered between labels and input fields within a containing div. Is it achievable using only relative lengths? Check out this jsfiddle fo ...

Facing issues with Uploadify: while trying to upload large files, encountering IO and HTTP errors

My current situation involves utilizing uploadify for the purpose of uploading large files, with a maximum size of 60MB. An issue I am currently facing is receiving an HTTP error when attempting to upload a 17MB file after it has been successfully uploade ...

Forms for uploading and submitting multiple files

On my single page, I have several file upload forms that are generated in a loop. The issue is that the first file upload control works fine, but the others do not. <div> <form action="/docs/1046/UploadDocument?Id=1046&amp;propertyTypeId ...

Is it possible to utilize LESS for CSS customization alongside Bootstrap 4 as the framework of choice?

Currently, I am in the process of transforming designs into responsive HTML and CSS for a project. Bootstrap 4 is my chosen framework and I have decided to include the CSS files rather than the SASS files. The ultimate goal is to integrate these coded pa ...

Set up a mouseover function for a <datalist> tag

Currently, I am delving into the world of javascript/jquery and I have set up an input field with a datalist. However, I am encountering a slight hurdle - I am unable to trigger an event when hovering over the datalist once it appears. Although I have man ...

Troubleshooting date range validation in jQuery

I am facing an issue in my code where I have a set of start and end date fields that need to be validated to ensure the start date comes before the end date. I am currently using the jQuery validation plugin for this purpose. For reference, here is the li ...

When does .ajaxComplete trigger in relation to the success callback?

Is there a method to determine whether the call was successful or not after it has been made? Alternatively, is there a way to execute a function after the success of each call if invoked before the call? ...

When the content div is clicked within the overlay div, the popup will also close

I want to design a pop-up that features a container with a black background and some opacity, where the content of the popup is placed inside. Here's what I have in mind: <button (click)="showPopup = !showPopup">Open popup</button& ...

Selecting multiple items in jQuery based on different attributes is a useful feature that

I am looking to choose multiple items based on their data attribute. Each item has a unique data-id. <div class="foo" data-id="1"></div> <div class="foo" data-id="2"></div> <div class=" ...

Is there a way to stop Ajax calls initiated with Dajaxice?

Utilizing Dajaxice with my Django-based website has proven to be highly convenient. However, I occasionally encounter the need to cancel Ajax requests and I'm unsure how to do so when they are wrapped with Dajaxice. The documentation for Dajaxice is ...

How can one set relative paths for links when including a file from a different directory that contains links?

My project directory is structured as follows: root css img src login login.php dashboard basic header.php footer.php profile.php manage.php department ...

Instructions on how to export an HTML table to Excel or PDF by including specific buttons using PHP or JavaScript

I created a table to display leave details of employees with sorting options from date to date. Now, I need to include buttons for exporting the data to Excel and PDF formats. Check out the code below: <form name="filter" method="POST"> <in ...

Dynamic container elements (already arranged)

After creating a marksheet generator, I noticed that the divs positioned over an image on the resulting page are not responsive when trying to print. The print preview ends up looking strange and distorted. How can I make these already positioned divs resp ...

In the realm of web development, the Phoenix library introduces the concept

Is there a way to combine a dynamic classname and a static one effectively? <div class=<%="#{getClass(app.status)} two" %> What happens is <div class="one" two> Instead of the desired output of <div class="one t ...