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

PHP is not compatible with cookies, however, they can be effectively used with Javascript

In order to view the cart of products, I am looking to initially load it using PHP and then handle subsequent updates or deletions through jQuery post requests. However, I am encountering an issue. [I receive variables in JSON format within the same PHP ...

The setting of background-size: cover does not affect the height of the background image

Looking for a solution to make a background image fill a div entirely? Here is the CSS code you can use: .class{ background-image: url('img.jpg'); background-repeat: no-repeat; background-size: cover; } You can implement this within t ...

Ways to center a spinner on the screen using CSS during loading

Upon loading the page, my spinner appears in the center of the screen after a second. However, in the initial frame of the page, it is not centered but positioned on the top-left corner instead. How can I ensure that my spinner starts off centered from the ...

Utilize the PHP variable HTTP_USER_AGENT to identify and analyze the user's browser

As I embark on creating a webpage, my goal is to have it display different content based on the user's browser. The SERVER [HTTP_USER_AGENT] variable initially seemed promising for this purpose, but upon inspecting the page in Chrome, I encountered: ...

Once invoked by an ajax request, the $().ready function is executed

The functionality of this code is flawless when running on its own. However, once I make an ajax call to it, the code fails to execute. I suspect that the issue lies within $().ready, but I haven't yet identified a suitable replacement. Any suggestio ...

Optimizing the position of the datepicker dropdown in Boostrap 4

I am currently utilizing Bootstrap 4 (final) with the boostrap-datepicker-plugin 1.7.1. Since Bootstrap 4 no longer uses .input-group-addon elements for the calendar icon, but instead .input-group-prepend and .input-group-append, I made some modificatio ...

How to display only the thumbnail on WordPress archive page and remove the post excerpt

I am currently in the process of revamping my category archive to resemble a grid layout by utilizing custom CSS. I have successfully eliminated the elements I desired using code like this: .archive .entry-footer { display: none; } Now, I only have t ...

Setting the minimum and maximum width of the MenuItem (popover) in Material-UI based on the width of the select component

I need the popover width to always match the width of the select component, regardless of the length of the text in the menu items. Setting autoWidth to either true or false is not providing a solution. Below is the code for the select component: import ...

Setting up the Bootstrap grid structure

Struggling to find the right configuration for this Bootstrap 3 setup... https://i.stack.imgur.com/ZsTdI.png I have an input field, but I'm having trouble placing the image in that position. <div class="row"> <div class="col-sm-4 col-m ...

Using Twitter Bootstrap to set a minimum number of lines for thumbnail captions

I currently have a carousel on my website created using Bootstrap that displays 4 columns of thumbnails. You can view the carousel here. When navigating to the third page of the carousel, you will notice that the container increases in height to accommodat ...

Creating a JavaScript function that responds to multiple click events

Can someone please help me out? I have the link to the output of my work below using JavaScript and HTML: My goal is for only one circle to be active when clicked, while the others are disabled. Currently, when I click on a circle and then another one, bo ...

Automatically activate the Focus Filterfield in the ng-multiselect-dropdown upon clicking

I've integrated the ng-multiselect-dropdown package into my Angular project using this link: https://www.npmjs.com/package/ng-multiselect-dropdown. Everything is functioning as expected, but I'm looking to automatically focus on the filter input ...

What steps should be taken when encountering the "Cannot Get" error message on a webpage?

Currently, I am in the process of creating an HTML file within xcode with the intention of displaying its contents in the browser. With an empty file as my starting point, the following code was added: <html> <head> <title>HTML is S ...

Cease the use of jQuery animations

My JavaScript code snippet looks like this: $.get("/<page>.php", "userid='.$userid.'&"+status, function(data){ $("#status").show("fast").html(data).delay(4000).hide("fast"); }); On a page with multiple links triggering thi ...

Troubleshooting AJAX issues in Firefox with window.location.assign function

Here is my AJAX POST request that sends serialized form data to the server: // Handle form submission. $('#evaluationform').on('submit', function(e){ e.preventDefault(); ajaxObject = { url: $("#evaluationform").attr("a ...

What is the best way to position a box in the center using CSS?

I have constructed a container using div and included 4 additional div elements inside: HTML: <div className='main__container'> <div className='item'>Image</div> <div className='item'>N ...

Limiting the amount of blogs shown on a single page can be achieved with Yii 1 and PHP

I have successfully implemented a feature to display blogs on one page. However, I now want to modify it so that only 5 blogs are shown per page and the user can click on a "next page" button to view the next set of 5 blogs. Here is the code snippet from ...

What could be causing my iframe to not adjust its size according to its content?

My attempt at resizing a cross-site iframe is not working as expected, despite following the guidance provided here. The iframe on my page seems to remain unaltered in size, and I can't figure out what mistake I might be making. The current location ...

What is the best way to navigate back on a button click in jquery AJAX without causing a page refresh?

Is there a way to navigate back without refreshing the page? I am fetching data dynamically using AJAX, but when I try to go back using the browser button, it takes me all the way back to the starting point. Let's look at the situation: 3 Different ...

Angular backslash is encoded

Experiencing the same issue as this individual: angularjs-slash-after-hashbang-gets-encoded The URL is getting encoded and not routing correctly, causing it to fall to the otherwise in my route config. I have not been able to identify the root cause yet, ...