Resolving Sticky State Issues with Multiple Sticky Headers in Divi

Written by Dan Mossop

When working with the Divi Theme Builder, it's quite common to create a custom header with multiple sections. You might want both sections to be sticky, but you may hit a snag with this setup: the first one starts off correctly as non-sticky, while the second one appears in the sticky state right away. This creates inconsistent styling as the sticky styles apply only to the second section instead of both upon initial load.

Here's an example of a two section header which is styled grey in its non-sticky state (this is how we'd want the header to display on page load). In its sticky state the sections are colored green and blue, which is how it displays after scrolling. Finally, we have the incorrect initial state which is what actually gets displayed on first page load – the top section is non-sticky and the bottom is in its blue sticky state:

Non-sticky State

Sticky State

Initial State (Incorrect)

Why does this happen in Divi?

Divi seems to treat the first section differently from other sticky sections. It allows the first section in your header to begin as non-sticky, which is great for single-section sticky header situations. This setup lets the header start in its regular state and become sticky as you scroll down. 

But, here's the problem: Divi also seems to anticipate other sticky situations, like social media bars that need to appear sticky immediately when the page loads in a scrolled state. Consequently, Divi tends to treat sections beyond the first as sticky content, which should be sticky 'right out of the gate' so to speak. This assumption means your second header section shows up as sticky immediately, since it's already in the position in the page at which it becomes sticky.

Hence you end up with the first section in a non-sticky state and the second section in a sticky state.

Fixing the Multi-Section Sticky Header

Don't worry; there's a couple of straightforward fixes to get your header sections behaving nicely.

Merge Sticky Sections

The first solution is to merge your header elements into one section. This ensures they share the same sticky behavior, starting as non-sticky and becoming sticky together as you scroll.

Adjust Sticky Settings

Another method is to tweak the settings of your second sticky section. By changing:

Section Settings > Advanced > Scroll Effects > Sticky Top Offset = -1px

…you essentially tell Divi, 'Don't go sticky until at least one pixel of scroll has occurred.' The result? The section begins as non-sticky and transitions to sticky just after a slight scroll – exactly what we want.

Conclusion

Handling multiple sticky sections in Divi Theme Builder can be a bit fiddly, but with a little know-how, you can ensure your header sections only become sticky when you intend them to. Whether you combine your header elements into a single section or adjust the Sticky Top Offset for the second section, you're now equipped to solve this sticky situation with ease. 

Optimizing Sticky Headers in Divi

Enhance your WordPress site with the WP Magic CTAs, designed to elevate user interaction on posts with advanced, automatic call-to-actions. Perfect for blog posts and sticky header tutorials like this, this tool ensures your CTAs are always engaging and effective. Limited offer: 50% off until Sept 5!

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.