What is causing the sticky navbar to not be able to scroll over divs with specific height and width?

Seeking assistance from anyone knowledgeable, as I am facing an issue with implementing a sticky navbar on my website. It functions properly over one section, but when there are multiple divs in another section, it no longer remains visible. Any recommendations or alternative solutions to prevent the navbar from disappearing? Despite trying the z-index suggestion, it did not resolve the problem. Is there a different approach to structuring the divs that could help avoid this issue? I came across a helpful resource that might provide some insights:

<ul>
  <li><a href="#home">About</a></li>
  <li><a href="#Blog">Blog</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a class="user" href="#about">My Program</a></li>
  <li><a class="user" href="#about">Progressions</a></li>

</ul>




 <div class="float-childL" style="max-width: 50%;">
      <img src="../images/2girls_yoga.jpg" alt="Girls yoga" style="max-width: 100%;">
    </div>
    
    <div class="float-childR" style="max-width: 50%;">
          <h1>TEXT</h1>
          <p>rhrhcjhrctjbrcbhcbhrcbhecbherbhrebhjerbchjebhjrxgvrfewhbfrehfrbhrfbjkwrjkfejnefjnebjcbjcncjbcebjcebjjbbjjbjbwcbhfebhebh</p>
          <br> 
          <br> 
          <br> 
    </div>


    <div class="float-childL" style="max-width: 50%;">
          <h1> TEXT</h1>
      </div>


      <div class="float-childR" style="max-width: 50%;">
        <img src="../images/trio.jpg" alt="male pushup" 
style="max-width: 100%;">
    </div>


    <div class="float-childL" style="max-width: 50%;">
      <img src="../images/male_plank.jpg" alt="plank" 
style="max-width: 100%;">
  </div>

  <div class="float-childR" style="max-width: 50%;">
    <h1> TEXT</h1>
</div>
    
    </div>









    ul {
      position: sticky;
      position: -webkit-sticky;
      list-style-type: none;
      margin: 0;
      margin-bottom: -20px;
      padding: 0;
      overflow: hidden;
      background-color: rgb(209, 111, 46);
      top: 0;
    }
    
    li {
  float: left;
  
}

     li a {
  display: block;
  color: white;
  text-align: center;
  padding: 22px 70px;
  text-decoration: none;
  
}

    li a:hover {
  background-color: #111;
}

    .user:hover { 
  background-color: rgb(255, 211, 130);
}

body:after {     
    content: ".";     
    display: block;      
    height: 0;      
    clear: both;      
    visibility: hidden; 
}


    .float-childL {
  float: left;
  text-align: center;
  overflow-wrap: break-word;
  background-color: blanchedalmond;
  padding: 20px;
  height: 500px;
  width: 50%;
  padding-top: 50px;
  padding-bottom: 50px;
  
}  


    .float-childR {
  float: right;
  text-align: center;
  overflow-wrap: break-word;
  padding: 20px;
  background-color: blanchedalmond;
  height: 500px;
  width: 50%;
  padding-top: 50px;
  padding-bottom: 50px;
  
}  

Answer №1

To solve this issue, try including a z-index: 2; in your sticky navbar's CSS and then add position: relative; z-index: 1; to the elements inside your floated div.

The reason behind this problem is likely that the floated divs are taken out of the standard page flow, making them appear on top of your sticky navbar.

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

Update the JavaScript to modify the styling based on the specific value of the

Is there a way to apply specific style properties to images only if they already have another property? I've managed to achieve this with the following code snippet: if ($('#content p img').css('float') == 'right') $ ...

Display or conceal content depending on the height of a div element

I need help with the following code. I want to hide the second paragraph by default and show it only when the blue circle is clicked and the div is expanded. Here is the code: What this code does is calculate the inner height of a specific element and s ...

Ways to adjust the visibility of a div element multiple times using javascript and css

I implemented a popup feature in my application: <div id="modal"></div> let modal = document.getElementById('modal') modal.innerHTML = ` <button class="close-button" onclick="close_modal()" ...

I am attempting to modify the background color of a div element without success. I need to create a new function specifically for changing the background

<html> <body> <input type="color" id="inputColor"> <input type="number" placeholder="Enter Number" id="inputDivNumber"> <button ...

Can you explain the distinction between locating an element by its class name versus locating it by its CSS selector?

Class name: var x = document.getElementsByClassName("intro"); CSS selector: var x = document.querySelectorAll("p.intro"); I'm a bit puzzled, are there any distinctions between the two methods or are they essentially the same? ...

Arrange the icons in multiple rows to ensure an equal distribution of icons on each row

There are 12 image icons displayed in a row within div elements using display: inline-block. However, when the browser window is resized, I would like the icons to be arranged on two or more rows so that each row contains an equal number of icons. ...

What is preventing the addition of links to the navigation bar when using a sticky navigation bar?

Currently, I am in the process of developing a blog website using Django. One of the features I have successfully implemented is a sticky navigation bar. However, I am facing a challenge with adding links to the menu on the navigation bar due to existing ...

Struggling to Adjust Image to Fit Within Parent Element

I recently started using bootstrap 4 to create a responsive website for practice. However, I encountered an issue with my image not resizing properly to fit the screen. <html lang="en"> <head> <!-- Required Meta Data --> ...

What is the best way to vertically center all content, including borders, within the columns?

To view the codepen for reference, please click on the following link: http://codepen.io/rezasan/pen/apvMOR I am attempting to align all the content within the columns (Date, Title, and Button, including the separator) vertically. I have tried using displ ...

What is the best way to dynamically adjust the size of a table or div when clicking in Angular 2?

Is there a way to dynamically resize a table or div in Angular 2 by clicking on a button or other element? I am attempting to change the width of a table from 300px to 100px using a function that utilizes CSS and TypeScript. table{ width: 300px; res ...

What is the best way to add two hyperlinks within a single tab of a Bootstrap navigation menu?

I attempted to place two links in one tab, but I was unsuccessful. Here is my navbar code: <!DOCTYPE html> <html lang="eng"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scal ...

Error encountered while generating PDF using xhtml2pdf Pisa.CreatePDF() due to CSS parsing issue

Currently, I am referencing the xhtml2pdf instructions. I opted to utilize one of the provided sample html files and saved it as test.html: <html> <head> <style> @page { size: a4 portrait; @frame header_frame { ...

Prevent all elements sharing the same class from expanding upon clicking if their parent element

Currently, I have implemented a function as a click event callback on a button. The purpose of this function is to toggle the class and provide a dropdown effect when the button is clicked. While this functionality works perfectly when the dropdown element ...

Freezing Columns and Rows for a Spacious Scrollable Table

After extensive effort, I have been diligently striving to create a solution that allows a table's column headers to scroll with the body horizontally and the first column to scroll with the rows vertically. While I've come across solutions that ...

Achieving a horizontal alignment of these four div elements containing images

I need some assistance with aligning the divs using the .acontainer class. It was working perfectly before adding the images, but now it's all messed up. I've tried various adjustments and searches online, but I'm still stuck. Thank you for ...

The Bootstrap collapsible menu isn't expanding all the way when clicked

I've hit a roadblock with a small issue that I can't seem to resolve. As a newcomer to bootstrap, I was working on programming the header with navigation when I encountered a problem that has me stumped. I'm reaching out for some assistance ...

Creating an Image slideShow with only one Image - making it slide on itself

Apologies for this confusing and vague question. Imagine I only have a single image, and I want to create a slideshow using technologies like Angular, jQuery, JavaScript, or just CSS. What I am aiming for is when the user clicks on my slide button, the i ...

Learn how to use CSS flexbox to easily vertically center items within a container with a full-height background

I'm having trouble with aligning text vertically centered within a box and making sure the background color stretches to full height. HTML: <div class="feature-content"> <div class="feature-visual"> <div class="embed-container"> ...

The CSS-styled button I created is designed to display a list and has the functionality of submitting

Whenever I click on a button, it's supposed to show a list of choices. But instead, it tries to submit the values in the text input field. Css .dropbtn { background-color: #3498DB; color: white; padding: 16px; font-size: 16px; border: none; cursor ...

Tips for employing Flex-grow alongside the behavior of "justify-content: start"

I am working with a flex container setup like this: .container { display: flex; flex-flow: row wrap; justify-content: start; width: 100%; } .item { border: 1px solid red; flex: 1 1 33%; height: 100px; } <div class="container"> <d ...