Creating Fixed Slide-In Header and Navigation in Divi 4

How to enable Fixed Navigation in Divi 4?

The long awaited Divi Theme Builder has arrived and we are now able to design our website headers using the Divi Builder. Unfortunately there is no setting (as of yet) to turn the Menu or Fullwidh Menu module into a fixed bar, that always stays visible on top of the page when you scroll down. So in this tutorial I’d like to show you a possible solution.

Making the header fixed at the top of the page

The simplest (though not really ideal) solution is to use this bit of CSS for your header section:

position:fixed;
top:0;
width:100%;
z-index:99;

You can add this code in the Advanced tab of the section settings (in the main element CSS box), and it will make your section “sticked” at the top of the page. Unfortunately this only works well if your header is narrow. But if your header area is big – making it fixed may not work well, as it might cover to much space of the browser window, especially on screens with smaller resolution.

Create a separate Slide-In section!

What I think would work well in some cases is an option to use a completaly separate design for the “fixed” header and keep a different look for the “normal” header. This is what I mean:

Read on for the step-by-step instructions on how to recreate this effect or, if you are a Divi Lover subscriber,  download the pre-designed header layouts with sleek slide-in navigation, which you can simply import and use on your projects!

Free Resources for Divi Lovers

Join our newsletter to get the good stuff!

We’ll provide you with updates on new tutorials, webdesign assets and special offers. Get top quality Divi goodies straight into your inbox! Read our Privacy Policy to learn how we manage and protect your submitted information.

Sign up to download

Get access to this layout and all the free resources made exclusively for our subscribers!

Already subscribed?

Fill the signup form and if you’re on the list it’ll get you straight to the download page!

Can’t see the form? Click here

Step 1. Create two header sections

This approach allows us to design a completaly different look for each header state. Let’s say you have two different logo images, a big one, used as a main logo in the centered navigation, and a horizontal logo version, which can be used for a slide-in fixed nav. Or, a different scenario, you don’t need the full navigation on the fixed nav – maybe you’d just like to keep a call to action button to draw your visitor attention. With two separate header sections possibilities are endless!

Create each section using the Divi Builder. Add a custom CSS class of dl-fixed-header to the second section. We are going to hide it with CSS and then use a simple JavaScript function to show it after the page has been scrolled by certain number of pixels.

Step 2. Add the CSS code

Add this CSS code to your Theme Options or your child theme stylesheet. Note that we are setting the top position to 0. Instead of moving it outside of the viewport with the top:-100% we are going to use the transform property with transalteY, which is apparently better/smoother to animate with transition (performance-wise).

body:not(.et-fb) .et_pb_section.dl-fixed-header {
	position:fixed;
	top:0;
	width:100%;
	transform: translateY(-100%);
	transition: 0.3s transform ease-in-out;
	z-index:99;
}

The :not(.et-fb) selector will make sure our header is being fixed only on the frontend and not when the Divi Builder is enabled, otherwise it might be a bit hard to access the section settings and other Builder controls.

The CSS code below will make sure the fixed section is dispayed correctly for the logged in users (when the admin bar is enabled):

body.admin-bar:not(.et-fb) .et_pb_section.dl-fixed-header {top:32px;}

@media (max-width:782px) {
	body.admin-bar:not(.et-fb) .et_pb_section.dl-fixed-header {top:46px;}
}

@media (max-width:600px) {
	body.admin-bar:not(.et-fb) .et_pb_section.dl-fixed-header {top:0;}
}

And the final bit of code, when the header gets a custom CSS class of dl-scrolled (which we are going to add dinamically with jQuery in a moment), this will transform it back to its default position:

body:not(.et-fb) .et_pb_section.dl-fixed-header.dl-scrolled {
	transform: translateY(0);
}

Step 3. Add the JavaScript

Add this jQuery code to the Code module on the page or to the Divi Theme Options -> Integration tab. You can also enqueue the custom JS file via your child theme. I wrote a separate blog post with detailed instructions on adding JavaScript code to Divi.

You can change the 150 value to one that matches your design. It is a number of pixel the page needs to be scrolled before the fixed header slides down.

<script>
jQuery(document).ready(function($){
	$(window).scroll(function(){
		var topOffset = $(window).scrollTop();
		var fixedSection = $('.dl-fixed-header');

		if (topOffset >= 150) {
			fixedSection.addClass('dl-scrolled');
		}
		else {
			fixedSection.removeClass('dl-scrolled');
   	   	}
	});
});
</script>

And that’s it! This is all the code you need to create a slide-in fixed section. Hope you’ll find it useful, I’d love to see how you implement this with your websites, share your headers in the comments below!

Grab the Free Slide-In Fixed Header Layouts!

I created a three different header designs, which Divi Lover subscribers can download and use on any Divi website! Each layout includes a standard and a fixed header sections with some custom styling. Check out the demo page and feel free to download the JSON files! 

Have you seen our

Divi child themes?

Divi Toolbox plugin?

We offer a great selection of high-quality Divi products to speed up your work. Feel free to use a coupon code IREADBLOG at the checkout to get a 10% discount!

34 Comments

  1. Treeshaped

    Thank you for this tutorial. Is there a way to include the Top Nav (secondary – the one with search and social icons) in Divi Theme Builder?

    Reply
  2. Wayne Dixon

    Vey nice, looking to use it on my next project, should I worry about the duplicate navigation and impact on SEO?

    Reply
    • Ania Romańska

      I am not an SEO expert, but I’d say there is not much to worry about. Of course, it would be ideal to use just one navigation and style it separately for mobile, but I don’t think that this method is going to hurt your Google rankings.

      Reply
      • Ania Romańska

        You should try setting the position of your header to fixed – that will move the rest of the page content below it.

  3. Maar

    I love your exemples, but they dont’t behave well with woocommerce category/tag pages. Any suggestion ?

    Thank you very much any way, very inspiring !!

    Reply
    • Ania Romańska

      Can you share a link on what exactly seems to be a problem?

      Reply
  4. Matt

    This trick was working until a Divi update to 4.5.3 (I was using it in 4.4.2)
    Any ideas on why that would be, or if you have experienced this?
    Need to update Divi because of the security issue.
    Thanks Ania!

    Reply
    • Ania Romańska

      Hi Matt, the demo page is working on Divi 4.5.5 with no issues.

      Reply
  5. Lori Newman

    Hi Ania, this is great! Thank you for this. How can I customize the dropdown menu font as well as make the submenu wider on theses menus?

    Reply
  6. Neil Bigwood

    Best post I have seen on the subject thank you so much

    Reply
  7. Shahid

    Awesome post. Thank you Ania

    Reply
  8. Kai

    What a great tutorial!
    But I have an issue when using a boxed layout. The fixed header runs out to the right on desktop and mobile view.
    And it kicks in way too late in mobile view.
    Is there any solution to that as I´m not an expert in css and Java… 😉
    Thanks and keep up the great work!
    Sincerely, Kai from Germany.

    Reply
      • Ania Romańska

        In the CSS, instead of

        width:100%;

        for the fixed-header use

        left: 0; right: 0;

        And you can change the offset value in the JS code to show it sooner. If you need different values for deskop and mobile you’d need to modify jQuery code and set different variables depending on the browser width. Maybe this will help.

  9. Gavin Fenton

    Thanks Ania, another great and above all practical tutorial. A usable solution for a common issue

    Reply
  10. Dustin Tantum

    What program are you using as your code editor?

    Reply
    • Ania Romańska

      I’m using Coda app (from Panic).

      Reply
      • sagar

        The Menu is not working on mobile it shows the # sign .
        please help out this layout is really very pretty I want to use it.

      • Ania Romańska

        The demo page seems to work fine, not sure what is happening on your site, would need to see it live, please share a link.

  11. Matthias

    Hi Ania, I love this Slide-In Fixed Header and it works fine on normal pages. But when I use it with Woocommerce-Pages, it no longer works and both sections are visible at the same time. Any Ideas how to fix it?

    Reply
    • Ania Romańska

      Can you share a link? The JS is most likely not being loaded on the page.

      Reply
      • Matthias

        Yes, I also think it´s a JS problem.

        I give you a link …

  12. Hurri

    Thanks Ania, thank you so much for yet another awesome tutorial for us!
    Even though I am a Divi Toolbox user (which makes my life a lot simpler) it is good to know how to do this.
    It’s seems simple and elegant and you explain it so well.

    Thanks so much for your efforts!

    Reply
    • Ania Romańska

      You’re welcome, Hurri. Thank you for your kind words 🙂

      Reply
  13. Inayat Meera

    Super cool! love this great work and ideas.
    Thank you…

    Reply
    • Ania Romańska

      Happy to help 🙂

      Reply
  14. Robin

    This is the best Christmas present anyone has ever given me!!! THANK YOU SOOOOOOO MUCH! Happy Holidays!

    Reply
    • Ania Romańska

      Glad you like it! 🙂

      Reply
  15. Matt

    Wow, this is better than what I was using so far! I have a question, when you add the position: fixed; with a Divi Global Header, it always moves the body content up and sometimes above the header. (I saw it happen in your video too.)
    What would you recommend as the best solution? I’m guessing you have to add top padding or margin to every page. Just wondering what you do as a fix for that.
    Thanks for the awesome tutorial – love how you even detail the code. (PS – looking at Divi Toolbox plugin now too.)

    Reply
    • Ania Romańska

      It does happen with the simple fixed (and always visible) header – the content is below the header. The simplest solution is to add enough top padding to first section on every page, but this Slide-in header does not have this issue, as standard (not fixed) header is always at the top. Hope this makes sense ^^

      Reply
  16. John Monahan

    This is great!

    Should be a standard part of Divi, along with the new theme builder. Very cool & easy to use. Thanks!!!!

    Reply
  17. Trish

    Thank you! This is a great solution, and I love the extra control I will have to design both headers. Will this be added to Toolbox?

    Reply
    • Ania Romańska

      I’m glad you like it 🙂
      It’s already available in Toolbox, check out the Header section (since ver. 1.5)

      Reply

Submit a Comment

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

Enjoing our content?

You might find this interesting…

License Details

REGULAR LICENSE

Single Site

A regular license allows an item to be used in one project for either personal or commercial use by you or on behalf of a client. The item cannot be offered for resell either on its own or as a part of a project. Distribution of source files is not permitted.

EXTENDED LICENSE

Unlimited Sites

An extended license allows an item to be used in unlimited projects for either personal or commercial use. The item cannot be offered for resell either on its own or as a part of a project. Distribution of source files is not permitted.

SUPPORT & UPDATES

Each license is a one-time payment. There are no annual fees. You get lifetime access to product updates. Support is provided for 6 months from the date of purchase.

Server Requirements

SERVER SETTINGS:

  • PHP 7.2 or later
  • upload_max_filesize (256M)
  • max_input_time (300)
  • memory_limit (256M)
  • max_execution_time (300)
  • post_max_size (512M)

PHP.INI SETTINGS:

  • php-xml or/and php-dom
  • XMLReader
  • PHP CURL module

PHP MODULES:

  • allow_url_fopen

Would you like to...

Consult Ania and fellow students?

Join the conversation inside our private FB group.

Would you like to...

Get support privately?

Submit a support ticket via your account page.

Ask Ania?

Submit a question for the next live Q&A session.

Consult fellow students?

Join the conversation inside our private FB group.