The z-index of the fixed header in FullPageJS is causing the section's content to be hidden

For my current project, I am incorporating FullPageJS and using a fixed top menu that adjusts its height based on the viewport size.

On smaller screens, the menu items will be stacked on top of each other, while on wider screens, the menu items will be positioned next to each other, resulting in varying heights for the menu.

I referred to the Fixed Elements demo from FullPageJS and noticed that by inspecting the "Fixed elements" h1 with Firefox dev tools and deselecting vertical-align:middle within .fp-tableCell, the text appeared to move under the fixed header.

In reality, the content was not moving but rather aligning itself at the top border of its container. This behavior occurs because the sections always occupy 100% of the viewport height, causing content within the sections that is not vertically aligned in the middle of a table cell element to be masked by fixed elements like a fixed navigation bar.

https://i.stack.imgur.com/Gc6q4.png

My goal is to have a fixed header or footer without the sections sliding beneath the fixed elements, but instead stopping at the boundary of the fixed element to prevent any obstruction of the section's content.

One approach could be inserting a placeholder element with the same height as the fixed element below it, positioning it within the flow of the section to restrict the section from slipping under the fixed element.

Waypoints Sticky Elements achieves this for dynamically generated sticky or fixed elements:

A wrapper is created around the element.

This wrapper remains static on the page, serving as an empty placeholder in the document flow while the actual element gains or loses fixed positioning.

The wrapper element acts as the element used in the underlying Waypoint functionality.

The wrapper's height is set to match the wrapped element's height, ensuring consistent alignment even when the element becomes fixed, thereby preventing layout shifts.

When the sticky element reaches the top of the window, a class is added. This class should be styled using CSS to provide fixed positioning to the sticky element.

Answer №1

Stop overcomplicating things.

1) Assign a class to your content container and add a margin-top to match the height of your header, which is approximately 60px. If the header has a variable height, consider using calc() in your CSS.

HTML: <div class="content-area">

CSS:

.content-area {
  margin-top: 60px;
  padding: 0 60px 60px;
}

2) Your header had multiple position declarations. For a fixed header, simply use position:fixed; Here's how it should look:

header {
    width: 100%;
    height: 50px;
    background-color: hsla(0, 0%, 20%, 1);
    box-shadow: 0px 2px 8px #222;
    position: fixed;
    top: 0;
}

3) The height of your menu items does not impact the header size based on my testing. It didn't require a z-index declaration either. Revisit your example for accuracy.

I made some adjustments to your code. It now functions properly, but your query seems unclear: http://jsfiddle.net/yaJyK/98/

Answer №2

https://i.stack.imgur.com/Q0hSP.png
The solution involving a placeholder to manage the fixed element within the layout was implemented successfully.

To achieve this, a div like dummy-buffer or placeholder is prepended to the .fp-tableCell class with the height matching that of the fixed element (referred to as navHeight in this case).

Setting the height of the placeholder equal to navHeight ensures that the fixed element no longer overlaps the content within the .section. An image demonstration showcases this behavior during transition.

Note: Adjustments were also made to the default fullPage.css rule for proper alignment of section content at the top.

.fp-tableCell {
  vertical-align:top !important;
}

$('.fp-tableCell').prepend($('<div class="dummy-buffer">DUMMY BUFFER</div>'));

var navHeightUpdate = function(){
    var navHeight = $('.navigation').outerHeight();
    console.log('Navigation Height = '+navHeight);
    $('.dummy-buffer').css('height',navHeight); 
};

navHeightUpdate();

View demo on JSFiddle

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

Enhancing functionality with extra JavaScript tags in next.js

Recently, I delved into programming with react & next.js after previously working with node.js. It didn't take long for me to create my first application, but upon inspecting the page, I noticed an abundance of extra JavaScript code (see image below). ...

Utilizing Isotope JS on your Wordpress website

I'm in the process of integrating the .js plugin, Isotope, into my Wordpress installation. It should be positioned at the bottom of this page: To achieve this, I am referring to an example on codepen: https://codepen.io/desandro/pen/mEinp The script ...

Obtain the ending section of a URL using JavaScript

Is it possible to extract the username from a URL like this example? I'm interested in seeing a regex method for achieving this. The existing code snippet only retrieves the domain name: var url = $(location).attr('href'); alert(get_doma ...

Could someone please clarify why the data I input is not appearing in my hbs file?

I've been facing an issue where I am unable to send data from my main.js file to bookings.hbs file, although it works perfectly fine when sending the same data to index.hbs file. Can someone help me identify where the error might be occurring? App.js ...

To view the contents of the dropdown list on an iPhone, simply tap the arrow key next to the mobile dropdown list and the contents will be

I am attempting to trigger the dropdown list contents to open/show by tapping on the arrow keys near AutoFill on the iPhone mobile keyboard. This action should mimic clicking on the dropdown itself. Currently, I am working on implementing this feature for ...

Construct a table featuring nested rows for every parent entry

Table 1 orderid customerName totalCost ---------------------------------- 1 Jonh £200.00 2 Ringo £50 Table 2 orderlineid orderid productName productPrice Quantity ----------------------------------------------- ...

I aim to generate a JavaScript string that, when placed within a div tag, will display as a list

I need assistance with formatting a string that contains a list of items to display in a specific way within a div tag using JavaScript. The string has multiple items that I wish to show as a bulleted list. Here is an example of the string: const items = & ...

Experience a seamless transition as the background gently fades in and out alongside the captivating text carousel

I have a concept that involves three background images transitioning in and out every 5 seconds. Additionally, I am utilizing the native bootstrap carousel feature to slide text in synchronization with the changing background images. Solving the Issue ...

Executing a PHP function every second using JS/Ajax: A step-by-step guide

Currently, I am utilizing the Highcharts API from to create a dynamic graph that reflects server load on my web panel. I have developed a PHP function called get_server_cpu_usage() which retrieves the current load data each time it is executed. My JavaS ...

Utilize JQuery function in ASP.Net and C# backend code

Is there a way to programmatically disable JQuery tabs? These tabs are located within an update panel (Ajax) on an ASP.NET page. Take a look at the code snippet below: <link type="text/css" rel="stylesheet" href="http://ui.jquery.com/testing/themes/ba ...

Remove child elements in Jquery that do not match the specific numbers saved in the array

I've got this array: var numbersArray = [1, 2, 4, 5] and also an unordered list in HTML <ul> <li> item 1 </li> <li> item 2 </li> <li> item 3 </li> <li> item 4 </li> <li> item 5 ...

Steps to insert a new row for a grid item using material-ui

When it comes to breaking a line of grid item like this, the image shown below illustrates how the rest space of the grid should be empty. https://i.stack.imgur.com/pvSwo.png <Grid container spacing={3} <Grid item xs={12}> "Grid Item xs ...

Refreshing backdrop for navigating through lists - Sprite edition

I am facing some issues while trying to use a sprite image for my navigation icons. The background position offset is not working as expected, and the background image is stretching across the whole length of the navigation. It seems like I may need to spe ...

Ways to protect Ajax link requests

Picture this scenario: a user is trying to register on a website and is filling out a form. As the user fills in the form, jQuery continuously validates fields using regular expressions, checks if they are valid, etc. The email address serves as the prima ...

Is it possible to dynamically alter CSS using PHP?

Here's a little query on my mind. Is it possible to dynamically alter the content of a CSS style using PHP in this manner? <?php header("Content-type: text/css; charset: UTF-8"); $color = "red;"; ?> header { color:<?php print $co ...

Is there a way to retrieve all CSS styles associated with a specific element?

When I come across a site element that I really like and want to incorporate into my own site, what is a simple way to do so? It can be challenging to navigate through numerous CSS files to find all the necessary styles. ...

When trying to use ngModel with Angular, an error occurs where the property 'selected' cannot be created on a string

I'm currently attempting to utilize [(ngModel)] in the following manner: <div class="items"> <tbody> <tr *ngFor="let info of this.information"> <td> <input type="checkbox" [(ngModel)]="this.info.n ...

Ways to prevent the need for multiple if/else statements and repetitious function instances

Check out this code snippet in Javascript: https://pastebin.com/zgJdYhzN. The purpose of the code is to fade in text when scrolling reaches a specific point. While it does work, I want to optimize it for multiple pages without creating separate instances ...

"Implementing master page and CSS styles on a child page: A step-by-step

Currently, I have a master page that is successfully being applied to all of my pages. However, it seems to be encountering an issue when trying to locate the CSS file address for pages within child folders. The folder structure looks like this: <scri ...

Several iFrames embedded on the website automatically adjust to the same pre-set height

Apologies if this question has already been addressed, but I am struggling to properly articulate it. Here's the issue: I have a client's holiday accommodation website that uses three embedded iFrames for a Calendar, Booking Enquiry, and floorpla ...