How to Automatically Generate Container Space for Your Fixed Divi Header (Using JQuery)

Last Updated on September 16, 2022 by 13 Comments

How to Automatically Generate Container Space for Your Fixed Divi Header (Using JQuery)
Blog / Divi Resources / How to Automatically Generate Container Space for Your Fixed Divi Header (Using JQuery)

When opting for a fixed header on your website, you’ll automatically find yourself using Divi and its built-in position options. The fixed position option inside Divi allows you to stick any element to a specific location on your page. When using a fixed position, however, the container space of your element is removed. The fixed header floats on top of your page content creating an overlap that you don’t necessarily want. To avoid this, you can generate container space for your section using a placeholder.

In this tutorial, we’ll show you exactly how to do that using some JQuery code. The code we’ll add at the end of this tutorial automatically calculates the container space of your custom-built header section and assigns that height to a new div around your header. You can use this JQuery code for any kind of header you built using one section. You’ll be able to download the JSON file for free as well!

Let’s get to it.


Before we dive into the tutorial, let’s take a quick look at the outcome across different screen sizes.


generate container space


generate container space

Download The Global Header Template for FREE

To lay your hands on the free global header template, you will first need to download it using the button below. To gain access to the download you will need to subscribe to our newsletter by using the form below. As a new subscriber, you will receive even more Divi goodness and a free Divi Layout pack every Monday! If you’re already on the list, simply enter your email address below and click download. You will not be “resubscribed” or receive extra emails.

1. Start Building Global Header Template

Go to Divi Theme Builder

Start by going to the Divi Theme Builder in the backend of your WordPress website and click on ‘Add Global Header’.

generate container space

Start Building Global Header

Continue by selecting the ‘Build Global Header’ option.

generate container space

2. Use One Section to Build The Entire Hero Section

Section Settings

Background Color

Now, in the next part of this tutorial, we’ll recreate the exact header design that was shown in the preview of this post. If you want, you can skip this part and go to the third part of this tutorial that shows you how to generate container space for your header section. If you, however, want to recreate the header section design as well, open the section settings of the section you can notice inside the template editor and add a background color.

  • Background Color: #6f4fff

generate container space

Background Image

Then, upload the background image you can find in the download folder that you were able to download at the beginning of this tutorial.

  • Background Image Size: Cover
  • Background Image Position: Center

generate container space


Remove the section’s default top and bottom padding next.

  • Top Padding: 0px
  • Bottom Padding: 0px

generate container space

Box Shadow

We’re using a subtle box shadow too.

  • Box Shadow Blur Strength: 80px
  • Shadow Color: rgba(0,0,0,0.3)

generate container space


And complete the settings by making the section fixed in the position settings.

  • Position: Fixed
  • Location: Top Center

generate container space

Add New Row

Column Structure

Once you’ve completed the section settings, continue by adding a new row using the following column structure:

generate container space


Without adding any modules yet, open the row settings and modify the sizing settings as follows:

  • Use Custom Gutter Width: Yes
  • Gutter Width: 2
  • Width: 100%
  • Max Width: 100%

generate container space


Modify the top and bottom padding across different screen sizes next.

  • Top Padding: 20px (Desktop), 0px (Tablet & Phone)
  • Bottom Padding: 20px (Desktop), 0px (Tablet & Phone)

generate container space

Main Element

And to align all column content, we’ll add two lines of CSS code to the row’s main element.

display: flex;
align-items: center;

generate container space

Hide Column 2 & 3 on Tablet & Phone

Last but not least, we’ll hide the second and third column on smaller screen sizes to limit the height of our header.

generate container space

  • Disable on: Phone & Tablet

generate container space

Add Menu Module to Column 1

Select Menu

Time to add modules, starting with a Menu Module in column 1. Select a menu of your choice.

generate container space

Upload Logo

Then, upload a logo.

generate container space

Remove Background Color

Remove the background color next.

generate container space


Move on to the design tab and make sure the following layout settings apply:

  • Style: Left Aligned
  • Dropdown Menu Direction: Downwards

generate container space

Menu Text Settings

Continue by modifying the menu text settings accordingly:

  • Menu Font: IBM Plex Sans Condensed
  • Menu Font Weight: Semil Bold
  • Menu Text Color: #dddddd (Desktop), #6f4fff (Tablet & Phone)
  • Menu Text Size: 0.8vw (Desktop), 2.5vw (Tablet), 3vw (Phone)

generate container space

Dropdown Menu Settings

Change the dropdown menu line color next.

  • Dropdown Menu Line Color: #ffffff

generate container space

Icons Settings

And change the hamburger menu icon color too.

  • Hamburger Menu Icon Color: #ffffff

generate container space


Then, navigate to the module’s spacing settings and add some custom margin values.

  • Bottom Margin: 0px
  • Left Margin: 10%
  • Right Margin: 10% (Tablet & Phone Only)

generate container space

Menu Logo CSS

Complete the Menu Module settings by adding some custom right margin to the menu logo CSS settings.


margin-right: 8vw !important;

Tablet & Phone:

margin-right: 0px !important;

generate container space

Add Text Module to Column 2

Add Content

In the second column, the only module we need is a Text Module. Add some copy of your choice.

generate container space

Add Link

Then, add a link.

generate container space

Text Settings

Move on to the module’s design tab and change the text settings as follows:

  • Text Font: IBM Plex Sans Condensed
  • Text Font Weight: Semi Bold
  • Text Color: #dddddd
  • Text Size: 0.8vw
  • Text Alignment: Right

generate container space


Modify the module’s sizing settings next.

  • Width: 45%
  • Module Alignment: Right

generate container space


Add some bottom padding too.

  • Bottom Padding: 1vw

generate container space


Along with a bottom border.

  • Bottom Border Width: 1px
  • Bottom Border Color: #dddddd

generate container space

Main Element

Complete the module settings by modifying the cursor using a single line of CSS code in the module’s main element.

cursor: pointer;

generate container space

Add Button Module to Column 3

Add Copy

In the third module, the only module we need is a Button Module. Add some copy of your choice.

generate container space

Button Settings

Move on to the module’s design tab and style the button accordingly:

  • Use Custom Styles For Button: Yes
  • Button Text Size: 0.7vw
  • Button Text Color: #ffffff
  • Gradient Color 1: #ffcfaa
  • Gradient Color 2: #fa6eb9
  • Gradient Type: Linear
  • Gradient Direction: 89deg

generate container space

  • Button Border Width: 0px
  • Button Border Radius: 4px
  • Button Font Weight: Bold

generate container space


Add some custom padding values next.

  • Top Padding: 0.8vw
  • Bottom Padding: 0.8vw
  • Left Padding: 1.5vw
  • Right Padding: 1.5vw

generate container space

Box Shadow

And complete the module settings by adding a box shadow.

  • Box Shadow Vertical Position: 20px
  • Box Shadow Blur Strength: 40px
  • Box Shadow Spread Strength: 0px
  • Shadow Color: rgba(252,160,177,0.7)

generate container space

3. Use JQuery Code to Create a Header Placeholder & Automatically Generate Container Space

Add CSS Class to Header Section

Now that we have all our modules in place, it’s time to generate container space for the header section. To do that, we’ll need to reopen the section settings and assign a CSS class to it. We’ll use this CSS class in our JQuery code to create a placeholder around the section and calculate the section’s height.

  • CSS Class: header-section-container

generate container space

Add Code Module to Column 1

Time to make the magic happen! Add a Code Module to the row’s first column.

generate container space

Insert JQuery Code

Place the JQuery code inside the Code Module and make sure you use script tags as you can notice in the print screen of the post.

var headerSection = $('.header-section-container');   
headerSection.wrap('<div class="header-placeholder"></div>');
var headerWrap = $('.header-placeholder');
var headerHeight = headerSection.outerHeight();
headerWrap.css('height', headerHeight);  
$(window).resize(function() {
  headerHeight = headerSection.outerHeight();
  headerWrap.css('height', headerHeight);

generate container space

Insert CSS Code

We’ll make one additional tweak on smaller screen sizes by adding some CSS code in between style tags as well.

.et_pb_column {
margin-bottom: 0px !important;

generate container space

4. Save All Theme Builder Changes and View Outcome on Website

The only thing left to do is save all theme builder changes and view the outcome on your website!

generate container space

generate container space


Now that we’ve gone through all the steps, let’s take a final look at the outcome across different screen sizes.


generate container space


generate container space

Final Thoughts

In this post, we’ve shown you how to automatically generate container space for your custom-built global header. By default, as soon as you turn an element fixed, the container space is removed and the element floats on top of your pages. This leads to an overlap with existing content at the top of your page, something which you might want to avoid. In this tutorial, we’ve used some JQuery code to automatically generate container space for your header. This code works for any kind of section header you build, as long as you add the CSS class to the section settings. You were able to download the JSON file for free as well! If you have any questions or suggestions, feel free to leave a comment in the comment section below.

If you’re eager to learn more about Divi and get more Divi freebies, make sure you subscribe to our email newsletter and YouTube channel so you’ll always be one of the first people to know and get benefits from this free content.

Divi Marketplace

Are You A Divi User? Find Out How To Get More From Divi! 👇

Browse hundreds of modules and thousands of layouts.

Visit Marketplace
Divi Marketplace
Divi Cloud

Find Out How To Improve Your Divi Workflow 👇

Learn about the new way to manage your Divi assets.

Get Divi Cloud
Divi Cloud
Divi Hosting

Want To Speed Up Your Divi Website? Find Out How 👇

Get fast WordPress hosting optimized for Divi.

Speed Up Divi
Divi Hosting
Premade Layouts

Check Out These Related Posts

Get a Free Butcher Shop Layout Pack for Divi

Get a Free Butcher Shop Layout Pack for Divi

Posted on April 15, 2024 in Divi Resources

Hey Divi Nation! Thanks for joining us for the next installment of our weekly Divi Design Initiative; where each week, we give away a brand new Layout Pack for Divi. This time around, the design team has created a beautiful Butcher Shop Layout Pack that’ll help you get your next Butcher Shop...

View Full Post


  1. Is there a way to disable the jquery function on mobile view? Or change it to footer section instead of header section? I’m asking this because of the rising demand of mobile navigations at the bottom of websites.

  2. Regardless of where I try to import the json file, it either rejects it with “This file should not be imported in this context.” or it hangs and just sits there. In the Support Centre, everything appears to be correct.

    • Same.

  3. Can you explain the JQuery?

    • Wow, I released an oddly similar tutorial a few days ago. But my code is simpler and works automatically without adding any CSS classes, if anyone wants that you can go to my Divi blog at Pee-Aye Creative.

  4. This worked while on my local environment. Soon as I tried to implement it on a live site (several) it wasn’t working. There is a bug in the Builder regarding the z-index an the positioning setting. Even though I tried this jQuery method, it did not work, the navigation header did not stay on top of the content of the page. Putting a z-index on the section as 999999…did not work. This is in the Builder global heading. I ended up copying the layout of the section with my rows and modules for the layout into the Divi Library. Then deleting the Global Heading in the Builder. Display none the #main-header. On each page, I added the saved navigation section to the top of the page adding the z-index, deleted out the jQuery code from this post. This works. Found the same problem with the Global Footer in the Builder, if the layout of your footer is high enough, the navigation falls under the footer content, not staying above the footer content. Like I said, there is a bug in the Builder regarding the Global Header and Footer…z-index/positioning issues.

  5. The author expects everyone using Divi to understand what Container Space means. There is NOT even an explanation or illustration as to how the Header will look like without the Container Space. To me, the demo looks exactly what Divi can do even without all the codes that the author suggested. Of course I know I’m mistaken. It’s because as a layman I can’t see the difference between Container and No Container simply by words.

    • So without this tutorial, the top of your page will go behind the header menu. Example, if your menu is 100px high, 100px of your first section will be cut off by the menu. This is the case if you’re using the Divi Theme Builder for your menu. If you’re not using the Theme Builder for this this generally isn’t an issue.

      This should be a feature built into Divi’s Theme Builder already. Hopefully they’re working on that.

    • I agree. There was never an example of what the problem looked like, only what it looked like after the rigmarole. Which, as you said, looks exactly like what we’ve come to expect Divi always does.

      I find often that terms are not explained under the assumption that all of us should know certain things. Which, obviously, we don’t.

  6. Shouldn’t this be a simple option in the theme builder? To switch on or off? I

  7. Wow, I didn’t know all of that. Cool! I love WP but sometimes it’s hard to imagine how big sites can be run with it. Your post shows that it’s really possible

  8. Does this still work if I have two or more sections in the header? If so, should all sections in the header have the class .header-section-container?

    • Same Problem =)

Leave A Reply

Comments are reviewed and must adhere to our comments policy.

Join To Download Today